0

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.

1
  • 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. Commented Oct 26, 2017 at 18:22

2 Answers 2

1

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");  
Sign up to request clarification or add additional context in comments.

3 Comments

You have 2 versions, and are using Class.forName to force loading, which add together to cause issues, only using the new one (without forcing loading) should fix it
I have recieved this error: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host InterfaceDSNdatabaseName=TTBOM, port 1433 has failed. Error: "null. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall." But I know that the DSN works because I can use the same DSN in Microsoft Access
Can you use something like wireshark to watch the connection and see what is happening?
0

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.

3 Comments

I have both drivers in my library
You should not. Get rid of the old one and keep only the one that is compatible with Java 8. In any case you should have one driver with version 4.2 or above.
I have recieved this error: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host InterfaceDSNdatabaseName=TTBOM, port 1433 has failed. Error: "null. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall." But I know that the DSN works because I can use the same DSN in Microsoft Access

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.