私は NetBeans IDE 7.0.1 を使用しており、Microsoft の JDBC を使用して Microsoft SQL Server 接続をテストしていました。私はこのテストプログラムを持っています:
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());
}
}
}
NetBeans VM Options プロパティを に設定してい-Djava.library.path=C:\lib
ます。
IDE でコードを実行すると、executeQuery でプログラムがフリーズし、「永久に」実行されます。エラーは返されず、タイムアウトも発生しません。
ただし、パッケージをビルドしてから実行するとjava -Djava.library.path=C:\lib -jar TestSQL.jar
、期待されるデータが返されます: Count = 7349
.