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

来源:2-4 数据库连接

qq_慕圣3596141

2019-03-12 15:29

String driver = "com.mysql.jdbc.Driver";

String url = "jdbc:mysql://locahost:3306/test0312?autoReconnect=true"; 

String user = "root";

String password = "123";

try {

Class.forName(driver);

Connection conn = DriverManager.getConnection(url, user, password);

String sql = "select ID,COMMAND,DESCRIPTION,CONTENT from message";

PreparedStatement statement = conn.prepareStatement(sql);

ResultSet rest = statement.executeQuery();

List<Message> list = new ArrayList<>();

while (rest.next()) {

Message message = new Message();

list.add(message);

message.setId(rest.getString("ID"));

message.setCommand(rest.getString("COMMAND"));

message.setContent(rest.getString("CONTENT"));

message.setDescription(rest.getString("DESCRIPTION"));

}

req.setAttribute("messageList", list);


写回答 关注

1回答

  • qq_慕圣3596141
    2019-03-12 17:32:27

    String url =“jdbc:mysql:// locahost:3306 / test0312?autoReconnect = true”; 

    这localhost书写错误

通过自动回复机器人学Mybatis---基础版

微信公众号自动回复功能学习Mybatis,基础教程加案例实战方式学习

107412 学习 · 786 问题

查看课程

相似问题