gpt4 book ai didi

Java - 错误 : A JNI error has occurred, ... 在线程 "main"java.lang.UnsupportedClassVersionError 中:

转载 作者:太空宇宙 更新时间:2023-11-03 11:26:16 25 4
gpt4 key购买 nike

目前我尝试在本地连接到我的 mysql 服务器。我的代码如下所示:

import java.sql.*; 

public class JdbcSelectTest {
public static void main(String[] args) {
try (
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/ebookshop?useSSL=false", "...", "...");

Statement stmt = conn.createStatement();
) {
String strSelect = "select title, price, qty from books";
System.out.println("The SQL query is: " + strSelect);
System.out.println();

ResultSet rset = stmt.executeQuery(strSelect);

System.out.println("The records selected are:");
int rowCount = 0;
while(rset.next()) { // Move the cursor to the next row, return false if no more row
String title = rset.getString("title");
double price = rset.getDouble("price");
int qty = rset.getInt("qty");
System.out.println(title + ", " + price + ", " + qty);
++rowCount;
}
System.out.println("Total number of records = " + rowCount);

} catch(SQLException ex) {
ex.printStackTrace();
}
}
}

现在当我编译时:javac JdbcSelectTest.java 一切正常。但是现在当我尝试运行编译时:java -cp .;C:\Users\Marco\IdeaProjects\mysql-connector-java-8.0.13\mysql-connector-java-8.0.13.jar 我收到以下错误:

Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.UnsupportedClassVersionError: JdbcSelectTest 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_HOME属性指向我本地安装的jdk版本11.0.1
mysql-connector-java 版本是:8.0.13
任何人都可以帮助我 - 顺便说一句。我是 Java 新手 - 所以任何评论都有帮助。

最佳答案

您的问题与 mysql 库无关。

错误消息中有意义的部分:

JdbcSelectTest has been **compiled by** [...] Java Runtime (class file version **55.0**)

对比

this [...] Java Runtime only **recognizes** class file versions up to **52.0**

这可以翻译成这样:

JdbcSelectTest由 Java 11 编译,但试图由 Java 8 运行

如果您想验证这一点,只需在您的控制台中输入以下这些命令:

:~ > java -version
:~ > javac -version

你会觉得它们是不同的。您已经检查了您的 JAVA_HOME 变量,但您还必须查看您的 PATH 变量以修复此问题。 This link会帮助你的。

关于Java - 错误 : A JNI error has occurred, ... 在线程 "main"java.lang.UnsupportedClassVersionError 中:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54185363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com