在MyEclipse中执行模糊查询,ResultSet结果集不为空但rs.next()为false,求解。
附代码:HttpSessionsession=request.getSession(true);Stringt_id=(String)session.getAttribu...
附代码:
HttpSession session = request.getSession(true); String t_id = (String) session.getAttribute("t_id");
List<Question> list = new ArrayList<Question>();
String condition = request.getParameter("condition");
String querySql;
if ("".equals(condition)) {
querySql = "select * from question1 where t_id=" + t_id;
} else {
condition = condition.trim();
querySql = "select * from question1 where ( question like '%"+ condition + "%' and t_id =" + t_id+")";
}
System.out.println(querySql);
Connection conn = MyDB.getConnection();
Statement stmt = MyDB.getStatement(conn);
ResultSet rs = MyDB.getResultSet(stmt,querySql);
if("".equals(rs)){
System.out.println( "ResultSet结果集为空!");
}else{
try {
while (rs.next()) {
Question q=new Question(); q.setId(rs.getInt("q_id"));
q.setQuestion(rs.getString("question"));
q.setChoice1(rs.getString("choice1"));
q.setChoice2(rs.getString("choice2"));
q.setChoice3(rs.getString("choice3"));
q.setChoice4(rs.getString("choice4"));
System.out.println(q.getId() + "--" + q.getQuestion() + "--"+ q.getChoice1() + "--" + q.getChoice2() + "--"+ q.getChoice3() + "--" + q.getChoice4() + "--");
list.add(q);
} request.setAttribute("modifyQuestion", list);
request.getRequestDispatcher("/modify.jsp").forward(request,
response);
} catch (SQLException e) {
e.printStackTrace();
}
在MySQL中该SQL语句执行正常 展开
HttpSession session = request.getSession(true); String t_id = (String) session.getAttribute("t_id");
List<Question> list = new ArrayList<Question>();
String condition = request.getParameter("condition");
String querySql;
if ("".equals(condition)) {
querySql = "select * from question1 where t_id=" + t_id;
} else {
condition = condition.trim();
querySql = "select * from question1 where ( question like '%"+ condition + "%' and t_id =" + t_id+")";
}
System.out.println(querySql);
Connection conn = MyDB.getConnection();
Statement stmt = MyDB.getStatement(conn);
ResultSet rs = MyDB.getResultSet(stmt,querySql);
if("".equals(rs)){
System.out.println( "ResultSet结果集为空!");
}else{
try {
while (rs.next()) {
Question q=new Question(); q.setId(rs.getInt("q_id"));
q.setQuestion(rs.getString("question"));
q.setChoice1(rs.getString("choice1"));
q.setChoice2(rs.getString("choice2"));
q.setChoice3(rs.getString("choice3"));
q.setChoice4(rs.getString("choice4"));
System.out.println(q.getId() + "--" + q.getQuestion() + "--"+ q.getChoice1() + "--" + q.getChoice2() + "--"+ q.getChoice3() + "--" + q.getChoice4() + "--");
list.add(q);
} request.setAttribute("modifyQuestion", list);
request.getRequestDispatcher("/modify.jsp").forward(request,
response);
} catch (SQLException e) {
e.printStackTrace();
}
在MySQL中该SQL语句执行正常 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询