为了账号安全,请及时绑定邮箱和手机立即绑定

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

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 回答

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

这localhost书写错误

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

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

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信