问题
I am trying to access a SQL Server database using Java and jtds. This is my (very) simple code:
String url = "jdbc:jtds:sqlserver://dev.company.com:1433/master;domain=COMP;USENTLMV2=true;SSL=request";
String driver = "net.sourceforge.jtds.jdbc.Driver";
String userName = "COMP\\username";
String password = "s3cr3t";
Connection conn = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(url, userName, password);
} catch (Exception e) {
e.printStackTrace();
} finally {
conn.close();
}
pom.xml
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.2.8</version>
</dependency>
After a few minutes of no activity, I get this error:
java.sql.SQLException: Network error IOException: Connection reset
....
Caused by: java.net.SocketException: Connection reset
....
I can ping dev.company.com, and I can access the database using a GUI (SQLPro for my Mac) so it's a valid connection, but I don't know what else to do.
回答1:
Please move away from JTDS. Their last release was ion 2012. As per one of the developers of JTDS (Nida ), the project has ceased all active development activities.
Please use SQLJdbc42 driver from Microsoft which is quite stable.
I am suffering from a JTDS issue with SQL Server on SSL and got the confirmation that this project is DEAD.
来源:https://stackoverflow.com/questions/43792672/cannot-access-sql-server-database-using-jtds