Unsupported version error using JTDS with Scala

stan picture stan · Nov 15, 2012 · Viewed 20k times · Source

I'm trying to use the Java JTDS driver to connect to my database in Scala . However, whenever I try to use it I get an error that the version(of java?) is wrong.

java.lang.UnsupportedClassVersionError: net/sourceforge/jtds/jdbcx/JtdsDataSource : Unsupported major.minor version 51.0

object DaoDriverAdaptor {
  import java.sql.{DriverManager, Connection}

  private def loadDriver() {
    try {
      Class.forName("net.sourceforge.jtds.jdbcx.JtdsDataSource")
    } catch {
      case e: Exception  => {
        println("ERROR: Driver not available: " + e.getMessage)
        throw e
      }
    }
  }
  • Scala version : 2.9.2
  • Java Version : 1.6
  • Using jtds 1.3.0
  • Output of java -version:

java version "1.6.0_35" Java(TM) SE Runtime Environment (build 1.6.0_35-b10-428-11M3811) Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01-428, mixed mode)

Answer

Tomasz Nurkiewicz picture Tomasz Nurkiewicz · Nov 15, 2012

Yes, your Java runtime is too old, according to Java class file format:

  • J2SE 7 = 51 (0x33 hex),
  • J2SE 6.0 = 50 (0x32 hex),
  • J2SE 5.0 = 49 (0x31 hex),
  • JDK 1.4 = 48 (0x30 hex),
  • JDK 1.3 = 47 (0x2F hex),
  • JDK 1.2 = 46 (0x2E hex),
  • JDK 1.1 = 45 (0x2D hex).

51.0 means you need Java 7 to run some of the classes in your project. And you are right it's jTDS that's causing the problem (from jTDS JDBC Driver 1.2.7 and 1.3.0 released):

Version 1.3.0 is the first Java 7 compatible version of the driver and

Either upgrade to Java 7 (always a good idea) or downgrade to some older jTDS driver.