You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GlassFish连接MySQL报错:密钥库异常致数据无法插入

Fixing MySQL Insert Failure in Java Web App (GlassFish + NetBeans)

Hey there, let's break down what's going on here. The error you're seeing (com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException) about the keystore file is the root cause of your inability to insert data into the users table. GlassFish is trying to establish an SSL connection to MySQL, but it can't access the keystore properly—either the file is corrupted, or the password is wrong. Let's fix this with these step-by-step solutions:

1. Disable SSL in Your JDBC Connection (Quickest Fix for Local Dev)

If you're working on a local development environment, you probably don't need an encrypted SSL connection to MySQL. Here's how to turn it off:

  • Open your JDBC connection configuration (either in NetBeans or GlassFish's admin console).
  • Modify your JDBC URL to add useSSL=false as a parameter. For example:
    jdbc:mysql://localhost:3306/testdb?useSSL=false
    
  • Save the changes and restart your GlassFish server. This should bypass the keystore check entirely and let your app connect to MySQL normally.

2. Fix the GlassFish Keystore Configuration (If You Need SSL)

If you do require SSL for your connection, you'll need to fix the keystore issue:

  • Check the keystore file: Navigate to C:\glassfish5\glassfish\domains\domain1\config and verify that keystore.jks exists. If it's missing or corrupted, you can regenerate it using the keytool command (part of the JDK), or restore it from a backup.
  • Verify the keystore password:
    1. Open the GlassFish Admin Console (default URL: http://localhost:4848).
    2. Go to Resources > JDBC > JDBC Connection Pools and select your connection pool.
    3. Switch to the Additional Properties tab and look for keyStorePassword. Make sure this matches the actual password for your keystore.jks file.
    4. If you need to update the password, use the GlassFish asadmin command line tool (located in C:\glassfish5\bin):
      asadmin set resources.jdbc-connection-pool.YourPoolName.additionalProperties.keyStorePassword=yourCorrectPassword
      
  • Restart GlassFish after making these changes.

3. Validate MySQL's SSL Settings

If your MySQL server isn't configured to use SSL, but your JDBC connection is forcing it, that'll cause the error too:

  • Log into your MySQL server and run this command to check SSL status:
    SHOW VARIABLES LIKE '%ssl%';
    
  • If have_ssl returns NO, MySQL isn't using SSL. You can either keep useSSL=false in your JDBC URL, or configure MySQL to enable SSL (follow MySQL's official docs for setting up SSL certificates).

4. Double-Check NetBeans Database Connection Config

Make sure the JDBC URL in NetBeans matches what's configured in GlassFish:

  • In NetBeans, right-click your database connection under the Services tab and select Properties.
  • Confirm the JDBC URL here has useSSL=false (or the correct SSL parameters if needed) and that all other details (username, password, port) are correct.

Once you fix the connection issue, your insert functionality should work as expected—since the problem was never with your users table or insert code, but with the database connection itself.

内容的提问来源于stack exchange,提问作者Timuçin ÇİÇEK

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 09:41:59