使用 JTDS 和 Scala 时出现不受支持的版本错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13403471/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unsupported version error using JTDS with Scala
提问by stan
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 JTDS 驱动程序连接到 Scala 中的数据库。但是,每当我尝试使用它时,我都会收到一个错误,指出(java 的?)版本是错误的。
java.lang.UnsupportedClassVersionError: net/sourceforge/jtds/jdbcx/JtdsDataSource : Unsupported major.minor version 51.0
java.lang.UnsupportedClassVersionError: net/sourceforge/jtds/jdbcx/JtdsDataSource : 不支持的major.minor版本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:
- 斯卡拉版本:2.9.2
- Java 版本:1.6
- 使用 jtds 1.3.0
- 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)
java 版本“1.6.0_35”Java(TM) SE 运行时环境(构建 1.6.0_35-b10-428-11M3811)Java HotSpot(TM) 64 位服务器 VM(构建 20.10-b01-428,混合模式)
回答by Tomasz Nurkiewicz
Yes, your Java runtime is too old, according to Java class file format:
是的,根据Java 类文件格式,您的 Java 运行时太旧了:
- 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).
- J2SE 7 = 51(0x33 十六进制),
- J2SE 6.0 = 50(0x32 十六进制),
- J2SE 5.0 = 49(0x31 十六进制),
- JDK 1.4 = 48(0x30 十六进制),
- JDK 1.3 = 47(0x2F 十六进制),
- JDK 1.2 = 46(0x2E 十六进制),
- JDK 1.1 = 45(0x2D 十六进制)。
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):
51.0 意味着您需要 Java 7 来运行项目中的某些类。没错,是 jTDS 导致了问题(来自jTDS JDBC Driver 1.2.7 和 1.3.0 发布):
Version 1.3.0 is the first Java 7 compatible version of the driver and
版本 1.3.0 是第一个 Java 7 兼容版本的驱动程序和
Either upgrade to Java 7 (always a good idea) or downgrade to some older jTDS driver.
升级到 Java 7(总是一个好主意)或降级到一些旧的 jTDS 驱动程序。
回答by a_horse_with_no_name
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.
如果您需要使用 Java 7 之前的 Java 版本,您应该只使用驱动程序的 jTDS 1.2.x 行。

