1

I'm trying to set a Resource inside my context.xml which contains all the information regarding the connection to the SQL Server database:

<Resource 
    name="jdbc/TestDB" 
    auth="Container" 
    type="javax.sql.DataSource"
    maxActive="25" 
    maxIdle="10" 
    maxWait="10000"
    removeAbandoned="true"
    removeAbandonedTimeout="300" 
    defaultAutoCommit="true"
    factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
    driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
    url="jdbc:sqlserver://myip;databaseName=mydb;integratedSecurity=true" 
/>  

And then I get my Connection object like this in code:

InitialContext ctx = new InitialContext();
DataSource datasource = (DataSource) ctx.lookup("jdbc/TestDB");
connection = datasource.getConnection();

But whenever I try to start my Tomcat server with Eclipse an exception is thrown in console:

Caused by: java.lang.UnsupportedClassVersionError: com/microsoft/sqlserver/jdbc/SQLServerDriver has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

Which makes no sense to me, as I have the JDK 1.8 (241) and I use this dependency in my maven:

<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>mssql-jdbc</artifactId>
    <version>7.2.2.jre8</version>
</dependency>

I made sure I had the right Java version on my project's build path.

The wierd thing is that the connection used to work when I got it like this:

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
connection = DriverManager.getConnection(connectionURL);

Any ideas on what could be causing this?

guillefix
  • 934
  • 1
  • 13
  • 30
  • 1
    As the duplicate link up top shows, you're running with Java 8 (52.0), but the JDBC driver is compiled for Java 11 (55.0). Check your Tomcat installation to see if it has another JDBC driver in its classpath, e.g. in the Tomcat `lib` folder. – Andreas Mar 04 '20 at 17:08
  • As I said before, my jdbc driver is built for jre8 (52.0) and not for jre11 (55.0). Look at the dependency I am using. It would make sense if I were using version 7.2.2.jre11, but that's not the case. – guillefix Mar 05 '20 at 08:24
  • Maybe that's what you believe, but the error message says you're wrong, since it specifically says that the `com.microsoft.sqlserver.jdbc.SQLServerDriver` class found on the classpath was compiled for Java 11. The jar file added by the `` shown in the question may not be the only JDBC driver jar file on the classpath. That why I suggested you check the runtime classpath for other JDBC driver jar files, e.g. added by the Tomcat installation. Of course, you could have added two different versions in your war file too. *So check it out!!* – Andreas Mar 05 '20 at 08:40

0 Answers0