gpt4 book ai didi

java - .MySQLNonTransientConnectionException : Could not create connection to database server

转载 作者:行者123 更新时间:2023-11-29 01:35:31 26 4
gpt4 key购买 nike

获取以下代码的错误

  package jdbcdrive;

import java.sql.*;
public class Lpt {

/**
* @param args
* @throws SQLException
*/
public static void main(String[] args) throws SQLException {

Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/lpt?autoReconnect=true&useSSL=false","root","2664");

Statement st = con.createStatement();

ResultSet rs = st.executeQuery("SELECT * FROM sys.lpt");

while(rs.next()) {

System.out.println(rs.getInt("BatchName")+" "+rs.getString("StudentName")+" "+rs.getString("StudentName")+" "+rs.getString("studentMobileNo")+" "+rs.getString("Address"));
}

}

}

我得到的输出错误是

Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

最佳答案

尝试将此添加到您的连接字符串中:

"useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC" 

对我有用

关于java - .MySQLNonTransientConnectionException : Could not create connection to database server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48556170/

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