java jdbc分页查询的时候,为什么查询结果是控制啊。。。

Java_Coder 发布于 2014/08/26 20:13
阅读 165
收藏 0
public List<Question> getQuestions(Integer userId, int page,
int pagesize) {

// TODO Auto-generated method stub
int star = pagesize * (page - 1);
String sql = " select Id,Describle,RightAnswer,UserAnswer,AnswerInfo,Time from question where UserId = " + 
userId + " LIMIT "+
Integer.toString(star) +"," + Integer.toString(pagesize);

DButil util = new DButil();
Connection conn = util.OpenConnection();
List<Question> questionlist = new ArrayList<Question>();

try {
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while(rs.next()){

Question question = new Question();
question.setId(rs.getInt(1));
question.setDescrible(rs.getString(2));
question.setRightAnswer(rs.getString(3));
question.setUserAnswer(rs.getString(4));
question.setAnswerInfo(rs.getString(5));
question.setTime(rs.getString(6));
questionlist.add(question);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
util.closeConn(conn);
}

if(questionlist==null){
return null;
}
return questionlist;

}




question表里有一个外键是userId,要查找确定userId的所有答题记录!!
加载中
返回顶部
顶部