在MyEclipse中执行模糊查询,ResultSet结果集不为空但rs.next()为false,求解。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在MyEclipse中执行模糊查询,ResultSet结果集不为空但rs.next()为false,求解。相关的知识,希望对你有一定的参考价值。
附代码:
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语句执行正常
以上是关于在MyEclipse中执行模糊查询,ResultSet结果集不为空但rs.next()为false,求解。的主要内容,如果未能解决你的问题,请参考以下文章
java中PreparedStatement执行带参数的sql语句如何实现模糊查询?
java中PreparedStatement执行带参数的sql语句如何实现模糊查询?
oracle 锁表问题 these query results are not updateable include the rowid to get updateable results