resultset为空的问题,好奇怪
数据库连接是成功的,打印出rs.next()为false,sql语句在sqlplus中能查到数据。有没人遇到这个问题,要怎么解决啊??
Java code:
public List getVoteList(int pageNo, int pageSize) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int currentNo1 = pageNo * pageSize;
int currentNo2 = (pageNo - 1) * pageSize;
String sql = "select * from (select rownum r,s.* from(select * from surveyinfo order by createtime)s "
+ "where rownum<="
+ currentNo1
+ ") where r>"
+ currentNo2
+ "";
List list = new ArrayList();
try {
conn = DbConn.getConnection();
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery(sql);
System.out.println(rs.next());
System.out.print(sql);
while (rs.next()) {
SurveyForm survey = new SurveyForm();
survey.setQid(rs.getInt("qid"));
survey.setQuestion(rs.getString("question"));
survey.setUserid(rs.getInt("userid"));
survey.setCid(rs.getInt("cid"));
survey.setCreateTime(rs.getDate("createdate"));
survey.setIscheck(rs.getInt("ischeck"));
survey.setOption1(rs.getString("option1"));
survey.setOption2(rs.getString("option2"));
survey.setOption3(rs.getString("option3"));
survey.setOption4(rs.getString("option4"));
survey.setOption5(rs.getString("option5"));
survey.setOption6(rs.getString("option6"));
survey.setOption7(rs.getString("option7"));
survey.setOption8(rs.getString("option8"));
survey.setOption9(rs.getString("option9"));
survey.setOption10(rs.getString("option10"));
list.add(survey);
}
} catch (
SQLException e) {
e.printStackTrace();
} finally {
DbConn.close(conn);
DbConn.close(pstmt);
DbConn.close(rs);
}
return list;
}
------解决方案--------------------
单步看一下你的pstmt对象执行的是什么sql,使用预编译这么写不是太规范吧,不知是不是这个问题
要是Statement对象应该可以这样写
------解决方案--------------------
------解决方案--------------------