javarsql-serverjdbcrjava

R to SQL Server Connection via JDBC - wrong version of driver


I'm trying to connect to SQL Server via JDBC (yes, I know ODBC is better, but I'd need to make changes to the server security do to that).

  library(RJDBC)
  library(rJava)
  drv <- JDBC("com.microsoft.sqlserver.jdbc.SQLServerDriver" , 
              "C:/SQL JDBC/sqljdbc_4.1/enu/jre7/sqljdbc41.jar" ,identifier.quote="`")

But I can't seem to find the right version of the driver:

Error in .jfindClass(as.character(driverClass)[1]) : 
  java.lang.UnsupportedClassVersionError: com/microsoft/sqlserver/jdbc/SQLServerDriver has been compiled by a more recent version of the Java Runtime (class file version 58.0), this version of the Java Runtime only recognizes class file versions up to 52.0

I've tried with drivers for 4.0, 4.1, 4.2, and 8.4:

https://learn.microsoft.com/en-us/sql/connect/jdbc/microsoft-jdbc-driver-for-sql-server-support-matrix?view=sql-server-ver15#java-and-jdbc-specification-support

I have 64-bit R and 64-bit Java installed on Windows 10.


Solution

  • The problem is that you have Java 8 installed on your machine, but Driver was build for java 14 (class file version 58.0 tells that).

    You can either install java 14 on your machine or get a JDBC driver for Java 8.

    A link for SQL Server JDBC driver for java 8