.MySQLNonTransientConnectionException:无法创建与数据库服务器的连接 [英] .MySQLNonTransientConnectionException: Could not create connection to database server
本文介绍了.MySQLNonTransientConnectionException:无法创建与数据库服务器的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
获取以下代码错误
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.
推荐答案
尝试将其添加到您的连接字符串中:
Try adding this to your connection String:
"useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC"
对我有用
这篇关于.MySQLNonTransientConnectionException:无法创建与数据库服务器的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文