我是 Java 世界的新手,虽然使用 NetBeans 代码创建 Web 应用程序工作正常,直到执行 get 方法,但当我尝试执行 SQL 查询时 glassfish 无法显示来自 MSQL DB 的数据并给出错误。我正在使用
在我的项目中创建了一个名为 GreetingServlet.java 的 servlet,应该执行该 servlet 以从图书馆数据库中获取数据。库正在运行。但我的代码在网络浏览器中显示错误,例如
HTTP Status 500 - Internal Server Error
type Exception report
messageInternal Server Error
descriptionThe server encountered an internal error that prevented it from fulfilling this request.
exception
jakarta.servlet.ServletException: Servlet Could not display records.
root cause
java.sql.SQLNonTransientConnectionException: Cannot open file:C:\Users\Subhranshu\glassfish7\glassfish\domains\domain1/config/keystore.jks [Keystore was tampered with, or password was incorrect]
root cause
com.mysql.cj.exceptions.SSLParamsException: Cannot open file:C:\Users\Subhranshu\glassfish7\glassfish\domains\domain1/config/keystore.jks [Keystore was tampered with, or password was incorrect]
root cause
java.io.IOException: Keystore was tampered with, or password was incorrect
root cause
java.security.UnrecoverableKeyException: Password verification failed
请找到我的代码:
Connection con;
con = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con =DriverManager.getConnection
//("jdbc:mysql://127.0.0.1:3306/library","root","");
("jdbc:mysql://localhost:3306/library","root","");
stmt = con.prepareStatement("select * from users where username = ? and password = ?");
stmt.setString(1, username);
stmt.setString(2, password);
rs = stmt.executeQuery();
MySQL 驱动程序默认使用安全连接 (SSL/TLS),这不能开箱即用,需要在 GlassFish 中进行一些配置。
如果您刚刚开始,我建议在驱动程序中禁用 SSL,使用以下连接 URL:
“jdbc:mysql://localhost:3306/library?useSSL=false”