emacs
emacs

Reputation: 101

execution stops with no errors thrown during jdbc connection

Just got done setting everything up and ran my code. but java doesn't throw any errors so I don't know what is wrong. Here is my setup win7 - sql server 2008 express r2 - eclipse-everything on one computer(localhost). Here is code:

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
        "databaseName=MyDatabase;user=sa;password=test;";
    System.out.println("AAA");

    Connection conn = DriverManager.getConnection(connectionUrl);

    System.out.println("BBB");

    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT * FROM Friends");

so up to printing AAA there are no errors thrown. Then nothing happens. No errors and BBB never prints. Something wrong with Connection conn declaration but what? No error messages at all so What should I look at now? Thanks

Upvotes: 1

Views: 1685

Answers (4)

emacs
emacs

Reputation: 101

After spending more than 8+ hrs on this problem, it all came down to stupid MS jdbc driver! I CAN'T BELIEVE THEIR OWN DRIVERS DON'T WORK WITH THEIR SOFTWARE!!! OMG. So after tons of searching it came down to using jtds jdbc driver and it works! sigh. Stay away from MS jdbc driver! I hope this can help others save some time.

Upvotes: 1

Bohemian
Bohemian

Reputation: 424993

My guess is that your sql server isn't running, and windows is timing out waiting for it to appear.

Confirm that the sql server is running, and confirm you can ping localhost.

Upvotes: 0

Sergey Gazaryan
Sergey Gazaryan

Reputation: 1043

Try check value of connectionUrl is right or not. Your waiting time until timeout of login to database when you call DriverManager.getConnection(connectionUrl) is DriverManager.getLoginTimeout(). Try check that value.

Upvotes: 1

Mike
Mike

Reputation: 318

Try wrapping the code around a try/catch, as shown below:

try {
  //your code here
} catch(SQLException e) {
  e.printStackTrace();
}

Within the 'catch' you should see some detail on what is going on.

A good tutorial on JDBC is located at http://www.jdbc-tutorial.com

Good luck!

Upvotes: 1

Related Questions