0
votes

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.

2
Aren't you missing a semicolon before database? See docs. Also, the keywords are not the same. Do not simply carry over ODBC params for JDBC params.Parfait

2 Answers

1
votes

What is happening

As the message says:

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.

This is because JDBC4.0 has a lot of changes, meaning you need to use a newer version of the driver. You cannot run the old driver on the new version.

How to fix it

Using just 6.2 or version 6.2.2.jre8 should fix the issue.

Extra info

You shouldn't need the below code after JDBC 4.0 (Java 1.6+)

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");  
0
votes

Starting with the Microsoft JDBC Driver 4.2 for SQL Server, Sun Java SE Development Kit (JDK) 8.0 and Java

You can read it here where you can find the requirements for the JDBC Driver.

So, you have to update your JDBC driver to v 4.2 at least. This is clear enough.