为什么rs.next()跳过列

gfttwv5a  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(406)

**结案。**此问题不可复制或由打字错误引起。它目前不接受答案。
**想改进这个问题吗?**更新问题,使其成为堆栈溢出的主题。

两年前关门了。
改进这个问题
我一直在尝试建立一个图形用户界面,从mysql数据库的图像,并显示一个接一个当下一步按钮被单击,它工作正常,除了它跳过一个图像,并显示一个接一个,我已经检查了同一行的id,id被跳过,以及所以我认为这是一个问题的mysql连接器。
方法示例:

  1. public Pair<Integer,Image> image2()throws SQLException
  2. {
  3. int id;
  4. System.out.println("I am in Image");
  5. try {
  6. System.out.println(rs);
  7. boolean anyResults = false;
  8. if (rs.next())
  9. {
  10. anyResults = true;
  11. Blob blob = rs.getBlob("image");
  12. id = rs.getInt("id");
  13. System.out.println(id);
  14. System.out.println(blob);
  15. System.out.println(blob.length());
  16. InputStream in = blob.getBinaryStream(1, blob.length());
  17. System.out.println(rs.next());
  18. System.out.println(in);
  19. BufferedImage image = ImageIO.read(in);
  20. System.out.println(image);
  21. Image image1 = SwingFXUtils.toFXImage(image,null);
  22. return new Pair<>(id, image1);
  23. }
  24. else if (!anyResults)
  25. {
  26. JOptionPane.showMessageDialog(null, "Not Found");
  27. }
  28. System.out.println("reached here");
  29. } catch (Exception e)
  30. {
  31. e.printStackTrace();
  32. }
  33. return null;
  34. }

下一个按钮示例:

  1. public void NextButtomClicked() throws SQLException
  2. {
  3. // this is what i used before => Image image1 = sql.image2();
  4. //Pair<Integer, Image> image1 = sql.image2();
  5. //Pair<Integer, Image> pair = sql.image2();
  6. Pair<Integer, Image> pair = sql.image2();
  7. Image image = pair.getValue();
  8. list.add(pair.getKey());
  9. this.imageView.setImage(image);
  10. }

ps.if(rs.next)的工作方式与while(rs.next)相同

dtcbnfnu

dtcbnfnu1#

system.out.println(rs.next());跳一排
尝试:

  1. public Pair<Integer,Image> image2()throws SQLException
  2. {
  3. int id;
  4. System.out.println("I am in Image");
  5. try {
  6. System.out.println(rs);
  7. boolean anyResults = false;
  8. boolean hasNext = rs.next();
  9. if (hasNext )
  10. {
  11. anyResults = true;
  12. Blob blob = rs.getBlob("image");
  13. id = rs.getInt("id");
  14. System.out.println(id);
  15. System.out.println(blob);
  16. System.out.println(blob.length());
  17. InputStream in = blob.getBinaryStream(1, blob.length());
  18. System.out.println(hasNext );
  19. System.out.println(in);
  20. BufferedImage image = ImageIO.read(in);
  21. System.out.println(image);
  22. Image image1 = SwingFXUtils.toFXImage(image,null);
  23. return new Pair<>(id, image1);
  24. }
  25. else if (!anyResults)
  26. {
  27. JOptionPane.showMessageDialog(null, "Not Found");
  28. }
  29. System.out.println("reached here");
  30. } catch (Exception e)
  31. {
  32. e.printStackTrace();
  33. }
  34. return null;
  35. }
展开查看全部

相关问题