0

I'm having an issue while trying to connect to an SQL Server 2008 database, here is the complete exception :

java.lang.UnsupportedClassVersionError: Bad version number in .class file (unable to load class com.microsoft.sqlserver.jdbc.SQLServerDriver)
    org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2531)
    org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1010)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1483)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1361)
    java.lang.ClassLoader.loadClassInternal(Unknown Source)
    java.lang.Class.forName0(Native Method)
    java.lang.Class.forName(Unknown Source)
    ma.ancfcc.dao.ConnexionSigest.getConnection(ConnexionSigest.java:120)
    ma.ancfcc.action.VerifyLoginAction.execute(VerifyLoginAction.java:70)
    org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
    org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
    org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
    org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

The exception is pointing to this line of code :

private static String DRIVER_SQLSERVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";

How can I solve this ?

5
  • The exception can't point to the line of code you claim. Commented Jan 6, 2014 at 16:07
  • @Kayaman why ? I verified this myself :) Commented Jan 6, 2014 at 16:20
  • Because the line is a String variable declaration, which can't produce that stack trace. Lukelazarovic is right in his answer. If you claim that it won't work with java 1.7, you're wrong again. You're giving out bad information, so it's difficult to help you. Commented Jan 6, 2014 at 16:22
  • Kayman is right, exception on the row with String declaration is nonsense. As I look at the stacktrace, it's obvious that this is the line in your code, where exception occurs: ma.ancfcc.dao.ConnexionSigest.getConnection(ConnexionSigest.java:120) Commented Jan 6, 2014 at 16:57
  • sorry I was wrong @lukelazarovic, the line of code where exception occurs is here Class.forName(DRIVER_SQLSERVER); Commented Jan 7, 2014 at 9:00

1 Answer 1

3

This exception is thrown when you try to load a class that was compiled with higher version of Java than the one you are running your application with.

See UnsupportedClassVersionError

  1. check the version of JVM you run your app with using java -version
  2. check the version of class file as suggested in how to check the jdk version used to compile a .class file - using javap -verbose com.microsoft.sqlserver.jdbc.SQLServerDriver
  3. If jar is intended to use with higher version of Java, you can either:
    • use higher version of JVM to run the app
    • download older version of driver
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @lukelazarovic, I'm running jre6, how can I know which version of JVM my SQL SERVER driver is compatible with ?... with the logic of your answer, if I use jre 1.7 I should not have any problem, which is not true for me, I'm still getting the same exception with jre 1.7.
I have updated my answer - try to find out what version the class file is and update your question with this information.

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.