gpt4 book ai didi

java - 异常:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:握手错误

转载 作者:行者123 更新时间:2023-11-29 23:46:14 24 4
gpt4 key购买 nike

我有以下java代码。

Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/shincy_intrn","shincy_intrn","shincy");
Statement st=con.createStatement();
int result=st.executeUpdate("insert into test(name)values('Swapna')");
if(result>0)
System.out.println("Inserted");

当我执行代码时,出现以下异常,

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Bad handshake
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4098)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4030)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:951)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1717)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1276)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2389)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2422)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2207)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:797)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at TestDb.main(TestDb.java:17)

我在linux服务器上使用eclipse和mysql5.5.38

最佳答案

确保目录和文件都具有相同的文件/目录所有权。

我在升级 gerrit 时遇到了这个问题,并尝试了所有可能性,最后发现 gerrit 下的一些目录和文件的所有者是 root,而不是启动 gerrit 的用户。

chmod -R 用户:组*

关于java - 异常:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:握手错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25927093/

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