This is an example of JDBC database query. It is strange that, after execution, only records with an even serial number can be queried. For example, if the database contains two data entries that meet the requirements, only the second data entry can be queried,
If there are four data entries that meet the requirements, only the second and fourth data entries can be queried, and so on ..
public ArrayList<Task> getPTask1(int userId) { try { ArrayList<Task> al = new ArrayList<Task>(); pstmt = (PreparedStatement) ct .prepareStatement("select * from task where receiverID = ? and publisherID = ? and remark = 2"); pstmt.setInt(1, userId); pstmt.setInt(2, userId); ResultSet rs = (ResultSet) pstmt.executeQuery(); while (rs.next()) { System.out.println(rs.next()); Task task = new Task(); task.setTaskId(rs.getInt(1)); task.setTopic(rs.getString(2)); task.setContent(rs.getString(3)); task.setAddition(rs.getBlob(4)); task.setUserByPublisherId(this.getUById(rs.getInt(5))); task.setUserByReceiverId(this.getUById(rs.getInt(6))); task.setDate(rs.getString(7)); task.setRemark(rs.getInt(8)); task.setLevel(rs.getString(9)); task.setAord(rs.getString(10)); task.setReason(rs.getString(11)); task.setDegree(rs.getString(12)); task.setAddName(rs.getString(13)); al.add(task); System.out.println("task4Content:" + task.getContent()); } return al; } catch (Exception e) { e.printStackTrace(); return null; }
The reason is:
Rs. Next is executed every time, and the pointer moves a row. Therefore, after you comment out system. Out. println (Rs. Next ();, it will be normal.