I'm trying to have a Java application talk to a Microsoft SQL Server database.
The client is Java 7. I've tried Java 8 as well with no difference.
public static void superSimpleJdbcTest(String jdbcUrl, String user, String password) throws SQLException { try (Connection dbConnection = DriverManager.getConnection(jdbcUrl, user, password)) { System.out.println("opened connection"); try (Statement statement = dbConnection.createStatement()) { System.out.println("created statement"); System.out.println("executing create table command..."); statement.execute("create table something (id int primary key, name varchar(100))"); System.out.println("completed create table command"); System.out.println("executing insert command..."); statement.executeUpdate("insert into something (id, name) values (1, 'Brian')"); System.out.println("insert command completed"); } } }
It sporadically works, but usually hangs on the create table command. If I comment out that, it hangs on the insert command. I can't imagine what is wrong.
When the SQLWorkbenchJ application was running, my simple Java test app, would open the connection and just hang forever on any SQL command without getting any errors.
As soon as I quit the SQLWorkbenchJ application, my simple Java test app ran perfectly as expected. That was really weird and I eventually stumbled on the answer.
I switched over to using RazorSQL as an SQL console and that doesn't seem to have any issues like this.
I have successfully used both the JTDS driver and the Microsoft driver (JDBC4). I have not tried the SQLWorkbenchJ , as I mostly use SQuirreL to test the drivers.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.