1

I am using NetBeans IDE 7.0.1 and was just testing a Microsoft SQL Server connection using JDBC from Microsoft. I have this test program:

package testsql;
import java.sql.*;
public class TestSQL {

    public static void main(String[] args) {
        Statement stmt = null;
        ResultSet rs = null;
        Connection con = null;

        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            String connectionURL = 
                    "jdbc:sqlserver://foo.bar.com:1433;" +
                    "databaseName=flintstone;integratedSecurity=true;";
            con = DriverManager.getConnection(connectionURL);
        } catch (SQLException e) {
            System.out.println("SQL Exception: " + e.toString());
        } catch (ClassNotFoundException e) {
            System.out.println("Class Not Found Exception: " + e.toString());
        }

        try {
            String SQL = con.nativeSQL("SELECT COUNT(*) AS Count FROM fred");
            stmt = con.createStatement();
            rs = stmt.executeQuery(SQL);
            while (rs.next()) {
                System.out.println("Count = " + rs.getString("Count"));
            }
        } catch (SQLException e) {
            System.out.println("SQL Exception: " + e.toString());
        }

    }
}

I have the NetBeans VM Options property set to -Djava.library.path=C:\lib.

When I run the code in the IDE the program freezes at executeQuery and runs 'forever'. No error is returned and a time-out is not raised.

However if I build the package and then run it with java -Djava.library.path=C:\lib -jar TestSQL.jar I get the expected data returned: Count = 7349.

2
  • Did you check the logs? Also you could keep a System.out.println() methods before and after your call to be certain that it's indeed hanging there.
    – Naidu Ypvs
    Aug 22, 2012 at 6:09
  • Yes I checked logs and used println() here, there and everywhere before I posted this question which is how I confirmed that it was the executeQuery() call that was freezing. Sep 11, 2012 at 10:12

1 Answer 1

0

I have the project working in the IDE now. It turned out to be the version of the JDK I was using. Replacing JDK1.6 with JDK1.7 fixed the problem, it works as expected now.

2
  • Most likely your JDK 1.6 was version 1.6 update 29 which had a bug which made connections to SQL Server freeze (JDK 1.7 Update 1 or 2 had the same issue btw). Aug 25, 2012 at 7:42
  • Mark, you are quite correct. It was version 1.6 update 29. I am now on version 1.7 update 6. Sep 10, 2012 at 11:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.