2012-11-15 12 views
22

Sto provando a utilizzare il driver JTDS Java per connettersi al mio database in Scala. Tuttavia, ogni volta che provo ad usarlo, ho un errore che la versione (di java?) È errata.Errore di versione non supportato utilizzando JTDS con Scala

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 
     } 
    } 
    } 
  • versione Scala: 2.9.2
  • Java Version: 1.6
  • Uso jtds 1.3.0
  • uscita di java -version: versione

java "1.6.0_35" Java (TM) SE Runtime Environment (build 1.6.0_35-b10-428-11M3811) Java HotSpot (TM) a 64 bit di server VM (build 20.10-b01-428, modalità mista)

risposta

40

Sì, il runtime Java è troppo vecchio, secondo Java class file format:

  • J2SE 7 = 51 (0x33 esadecimale),
  • J2SE 6.0 = 50 (0x32 esadecimale),
  • J2SE 5.0 = 49 (0x31 esadecimale),
  • JDK 1.4 = 48 (0x30 esadecimale),
  • JDK 1.3 = 47 (0x2F lui x),
  • JDK 1,2 = 46 (0x2E hex),
  • JDK 1.1 = 45 (0x2 hex).

51.0 significa che è necessario Java 7 per eseguire alcune delle classi nel progetto. E hai ragione è jTDS che sta causando il problema (da 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

effettuare l'aggiornamento a Java 7 (sempre una buona idea) o downgrade a un certo driver jTDS anziani.

+1

Scala non è ancora compatibile al 100% con JDK7, quindi mi bastone per il driver più vecchio, per ora. Grazie! –

10

Dal 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.

Problemi correlati