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);
String url =“jdbc:mysql:// locahost:3306 / test0312?autoReconnect = true”;
这localhost书写错误