com/microsoft/sqlserver/jdbc/SQLServerDriver has been compiled by a more recent version of the Java Runtime

折月煮酒 提交于 2021-02-10 06:23:15

问题


I has db in MS SQL Server 2005

I has java project write on java 8. My project is on Windows 7 Professional's machine (64 bit).

I use this jar: sqljdbc4.jar to connect to MS SQL Server 2005.

But when I start my app I get error:

 [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)

Here my app's snippet:

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);

        }

Error in this line:

Class.forName(driverName); // ERROR IN THIS LINE

comment:

driver name=com.microsoft.sqlserver.jdbc.SQLServerDriver

P.S. I can't upgrade to jdk 9. I can use only jdk 8

来源:https://stackoverflow.com/questions/56304767/com-microsoft-sqlserver-jdbc-sqlserverdriver-has-been-compiled-by-a-more-recent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!