I’ve got an application, where I use a JDBC connection. When I run it from the Eclipse environment, there’s no problem with anything, neither with connection.
But, when I pack it into executable jar file, and run it from command line, while calling the line
DriverManager.getConnection(url, user, password);
with correct credentials, the application gets frozen. (With wrong login attempt everything is ok – the SQLServerException is thrown).
I tried to create the jar file with different library choices, but the result is the same.
Can anyone help?
I use sqljdbc4.jar library
Constructor of my Database class:
public Database(String url, String user, String password) throws SQLException, ClassNotFoundException {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("forname");
connection = DriverManager.getConnection(url, user, password);
System.out.println("get connection");
}
After correct login no Exception is thrown and “get connection” string is not printed out (only “forname” string is printed)
Are you using Java 6 Update 29? If so Update to Java 6 Update 30 or higher (preferably the latest: Update 32). There was a bug in that Java version which caused the Microsoft SQL Server JDBC driver to hang.