MySql 连接错误 (Java.lang.VerifyError) (IDE: Netbeans)

MySql Connection Error (Java.lang.VerifyError) (IDE: Netbeans)

我正在将我的项目连接到 Wampserver。同一项目使用相同的代码和方法与其他系统中的数据库连接,但是当我在我的系统上尝试它时,它显示以下错误消息:

  run:
 java.sql.SQLException: java.lang.VerifyError: (class: com/mysql/jdbc/DatabaseMetaData, method: supportsRefCursors signature: ()Z) Illegal use of nonvirtual function call
 java.sql.SQLException: java.lang.VerifyError: (class: com/mysql/jdbc/DatabaseMetaData, method: supportsRefCursors signature: ()Z) Illegal use of nonvirtual function call
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:435)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:404)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)
at java.sql.DriverManager.getConnection(DriverManager.java:619)
at java.sql.DriverManager.getConnection(DriverManager.java:244)
at sea.DBClass.ConnectDB(DBClass.java:30)
at sea.Interface.jButton1ActionPerformed(Interface.java:63)
at sea.Interface.access[=13=]0(Interface.java:13)
at sea.Interface.actionPerformed(Interface.java:38)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6513)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3322)
at java.awt.Component.processEvent(Component.java:6278)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4869)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4691)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4834)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4494)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4424)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2721)
at java.awt.Component.dispatchEvent(Component.java:4691)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:722)
at java.awt.EventQueue.access0(EventQueue.java:103)
at java.awt.EventQueue.run(EventQueue.java:681)
at java.awt.EventQueue.run(EventQueue.java:679)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.security.ProtectionDomain.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue.run(EventQueue.java:695)
at java.awt.EventQueue.run(EventQueue.java:693)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:692)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
BUILD SUCCESSFUL (total time: 8 seconds)

我的连接代码如下:

  public class DBClass {

public static Connection ConnectDB (){

    try{
String url = "jdbc:mysql://localhost:3306/";
String DBName = "sea";
String Drivers = "com.mysql.jdbc.Driver";
String user ="root";
String pass = "";
Class.forName(Drivers);

        java.sql.Connection con = DriverManager.getConnection(url+DBName,user,pass);
JOptionPane.showMessageDialog(null, "Connectd");
return con;

}catch (Exception e){
JOptionPane.showMessageDialog(null,e);
e.printStackTrace();
return null;
}

在 try catch 中捕获的异常如下:

" ERROR java.sql.SQLException: java.lang.VerifyError: (class: com/mysql/jdbc/DatabaseMetaData, method: supportsRefCursors signature: ()Z) Illegal use of nonvirtual function call "

您可以安装 Java Lambda 版本。 Java lambda 版本解决了这个问题。 https://jdk8.java.net/lambda/