Unsupported version error using JTDS with Scala
Asked Answered
L

2

22

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)

Lynsey answered 15/11, 2012 at 18:3 Comment(0)
A
40

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.

Associative answered 15/11, 2012 at 18:10 Comment(1)
Scala still isn't 100% compatible with JDK7, so I'll stick to the older driver for now. Thanks!Lynsey
I
10

From the release notes:

You should only stick to the jTDS 1.2.x line of the driver if you require to use Java versions prior to Java 7.

Impasse answered 15/11, 2012 at 18:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.