gpt4 book ai didi

java.sql.SQLNonTransientConnectionException: Cannot open file:keystore.jks [Keystore was tampered with, or password was incorrect](异常:无法打开文件:keystore.jks[密钥库被篡改,或密码不正确])

转载 作者:bug小助手 更新时间:2023-10-26 21:08:15 32 4
gpt4 key购买 nike



I am new to Java world, while creating a webapp using NetBeans code is working fine till get method is executed but when I am trying to execute the SQL query glassfish is unable to show data from MSQL DB and giving errors. I am using

我是Java世界的新手,虽然使用NetBeans代码创建Web应用程序工作正常,直到执行get方法,但当我试图执行SQL查询时,glassfish无法显示来自MSQL DB的数据并给出错误。我正在使用



  • Apache NetBeans IDE 18

  • JDK20

  • Glassfish 7.0.3

  • MySQL 8.0 CE

  • windows10


In my project created a servlet called GreetingServlet.java which should get executed to fetch data from library database. library is running. But my code is showing errors in web browser like

在我的项目中,创建了一个名为GreetingServlet.Java的Servlet,应该执行该Servlet来从库数据库中获取数据。库正在运行。但我的代码在Web浏览器中显示错误,如


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

Please find my code:

请找到我的代码:


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

更多回答

Does this maybe help?

这可能有帮助吗?

优秀答案推荐

The MySQL driver uses secure connection (SSL/TLS) by default, which doesn't work out of the box and requires some configuration in GlassFish.

默认情况下,MySQL驱动程序使用安全连接(SSL/TLS),这不是开箱即用的,需要在GlassFish中进行一些配置。


If you're just getting started, I recommend to disable SSL in the driver, with this connection URL:

如果您刚刚开始,我建议您禁用驱动程序中的SSL,连接URL如下:


"jdbc:mysql://localhost:3306/library?useSSL=false"

“jdbc:mysql://localhost:3306/library?useSSL=false”


更多回答

Just for reference, if you'd like to use SSL, you need to specify the following property in the JVM config: -Djavax.net.ssl.keyStorePassword=changeit, where "changeit" is the default password for the GlassFish certificte stores, and you'll also need to add the public key from the MySQL server into GlassFish so that it's trusted by GlassFish. But you only need to do this in production if you want to secure the communication between GlassFish and MySQL.

仅供参考,如果您希望使用SSL,则需要在JVM配置中指定以下属性:-Djavax.net.ssl.keyStorePassword=changeit,其中“changeit”是GlassFish证书存储的默认密码,您还需要将MySQL服务器中的公钥添加到GlassFish中,以便GlassFish信任它。但是,如果您想要保护GlassFish和MySQL之间的通信,则只需在生产中执行此操作。

You'll need to add the certificate from the MySQL server into Glassfish's truststore, if it isn't signed by a CA.

如果证书不是由CA签署的,则需要将证书从MySQL服务器添加到GlassFish的信任库。

Yes, I’m sorry, I meant the certificate, not the public key.

是的,对不起,我指的是证书,不是公钥。

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