GlassFish连接MySQL报错:密钥库异常致数据无法插入
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=falseas 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\configand verify thatkeystore.jksexists. If it's missing or corrupted, you can regenerate it using thekeytoolcommand (part of the JDK), or restore it from a backup. - Verify the keystore password:
- Open the GlassFish Admin Console (default URL:
http://localhost:4848). - Go to
Resources > JDBC > JDBC Connection Poolsand select your connection pool. - Switch to the
Additional Propertiestab and look forkeyStorePassword. Make sure this matches the actual password for yourkeystore.jksfile. - If you need to update the password, use the GlassFish
asadmincommand line tool (located inC:\glassfish5\bin):asadmin set resources.jdbc-connection-pool.YourPoolName.additionalProperties.keyStorePassword=yourCorrectPassword
- Open the GlassFish Admin Console (default URL:
- 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_sslreturnsNO, MySQL isn't using SSL. You can either keepuseSSL=falsein 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
Servicestab and selectProperties. - 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

