Key notes:
- Using SQL Server 2005
- Using JDK 1.8
- JDK 1.8 DOES NOT SUPPORT JDBC-ODBC Bridge ANYMORE
- I have both Microsoft SQLJDBC 4.0 and 6.2 in my library
I am trying to connect to a remote SQL Server in Java for quite some time now and still have not been able to. I am hoping to connect using my DSN that I have created. The new driver JDK 1.8 uses needs a connection URL which I have created below. Everything in the code below looks correct. But I am still getting the error:
SEVERE: Java Runtime Environment (JRE) version 1.8 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0. java.lang.UnsupportedOperationException: Java Runtime Environment (JRE) version 1.8 is not supported by this driver.
Use the sqljdbc4.jar class library, which provides support for JDBC 4.0.
Here is my code:
String connectionUrl = "jdbc:sqlserver://InterfaceDSN" +
"databaseName=DB_Local;Trusted_Connection=True;integratedSecurity=true";
// Declare the JDBC objects.
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);
String SQL = "SELECT TOP 10 * FROM Person.Contact";
stmt = con.createStatement();
rs = stmt.executeQuery(SQL);
while (rs.next()) {
System.out.println(rs.getString(4) + " " + rs.getString(6));
}
}catch (Exception e)
{
e.printStackTrace();
}
To conclude: Knowing what I have and what I need, is there another way to connect to the database, I am running out of options here considering I am using JDK 1.8 with SQL Server 2005.