Why does JDBC query MySQL display records with an even number?

Source: Internet
Author: User
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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.