我在MS SQL Server 2005中拥有数据库
我在 java 8 上编写了Java项目。我的项目在 Windows 7 Professional的计算机(64位)上。
我使用以下jar:sqljdbc4.jar
连接到 MS SQL Server 2005 。
但是当我启动我的应用程序时,出现错误:
[java] log4j: setFile ended
[java] log4j: Appender [File] to be rolled at midnight.
[java] log4j: Adding appender named [File] to category [root].
[java] [25.05.2019 15:11:44.979] com.myproject.common.LNFSetter.setLNF(LNFSetter.java:60) TRACE:
[java] lookAndFeelName=Windows
[java] lookAndFeelClassName=com.sun.java.swing.plaf.windows.WindowsLookAndFeel
[java] Exception in thread "main" java.lang.UnsupportedClassVersionError: com/microsoft/sqlserver/jdbc/SQLServerDriver has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
[java] at java.lang.ClassLoader.defineClass1(Native Method)
[java] at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
[java] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[java] at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
[java] at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[java] at java.lang.Class.forName0(Native Method)
[java] at java.lang.Class.forName(Class.java:264)
[java] at com.myproject.db.DBManagerContext.initConnection(DBManagerContext.java:69)
[java] at com.myproject.db.DBManagerContext.initialize(DBManagerContext.java:94)
[java] at com.myproject.db.DBManagerContext.<init>(DBManagerContext.java:102)
[java] at com.myproject.db.DBManagerContext.getInstance(DBManagerContext.java:115)
[java] at com.myproject.common.SystemOptions.getDBManagerContext(SystemOptions.java:382)
[java] at com.myproject.m2document.M2DocumentManager.initialize(M2DocumentManager.java:42)
[java] at com.myproject.m2document.M2DocumentManager.<init>(M2DocumentManager.java:60)
[java] at com.myproject.m2document.M2DocumentManager.getInstance(M2DocumentManager.java:35)
[java] at com.myproject.views.ca.scroller.AccountsScroller.init(AccountsScroller.java:182)
[java] at com.myproject.views.ca.scroller.AccountsScroller.<init>(AccountsScroller.java:160)
[java] at com.myproject.views.ca.MainScreenView.<init>(MainScreenView.java:103)
[java] at com.myproject.Main.<init>(Main.java:42)
[java] at com.myproject.Main.main(Main.java:54)
这是我的应用程序的摘录:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
private void initConnection(String suffixURL) throws ClassNotFoundException, SQLException {
String driverName = UserOptions.getOptionsDBDriverName();
Class.forName(driverName); // ERROR IN THIS LINE
String url = null;
String databaseType = UserOptions.getOptionsDBURLType();
String host = UserOptions.getOptionsDBURLHost();
String port = UserOptions.getOptionsDBURLPort();
String databaseName = UserOptions.getOptionsDBURLName();
if (suffixURL == null) {
url = UserOptions.getOptionsAdditionalDBURL(databaseType, host, port, databaseName);
} else {
url = suffixURL;
}
String userName = UserOptions.getOptionsDBUserName();
String password = UserOptions.getOptionsDBPassword();
connection = DriverManager.getConnection(url, userName, password);
}
此行中的错误:
Class.forName(driverName); // ERROR IN THIS LINE
评论:
driver name=com.microsoft.sqlserver.jdbc.SQLServerDriver
P.S。我无法升级到 jdk 9 。我只能使用 jdk 8