Statement.setString(,);不工作
请问我的Statement.setString(1,"查看");不工作?很无语 就算我把这里的第二个参数变成常量字符串也没办法工作,查询不出东西 求解!!!!!!急
req.setCharacterEncoding("UTF-8");
String command=req.getParameter("command");
String description=req.getParameter("description");
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/micro_message","root","123456");
StringBuilder sql=new StringBuilder();
sql.append("select * from message where 1=1");
List<String> paramList=new ArrayList<>();
if(command!=null&&!"".equals(command.trim())){
sql.append(" and COMMAND=?");
paramList.add(command);
}
if(description!=null&&!"".equals(description.trim())){
sql.append(" and description like '%'?'%'");
paramList.add(description);
}
PreparedStatement Statement= conn.prepareStatement(sql.toString());
for(int i=0;i<paramList.size();i++){
Statement.setString(i+1,paramList.get(i));
}
ResultSet rs=Statement.executeQuery();
List<Message> messageList=new ArrayList<>();
while (rs.next()) {
Message message=new Message();
message.setId(rs.getInt("ID"));
message.setCommand(rs.getString("COMMAND"));
message.setContent(rs.getString("CONTENT"));
message.setDescription(rs.getString("DESCRIPTION"));
messageList.add(message);
}
req.setAttribute("messageList", messageList);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
req.getRequestDispatcher("/WEB-INF/jsp/back/list.jsp").forward(req, resp);