gpt4 book ai didi

java - 为什么 rs.Next() 跳过列

转载 作者:行者123 更新时间:2023-11-30 21:43:33 24 4
gpt4 key购买 nike

<分区>

我一直在尝试构建一个 GUI,它从 MySQL 数据库中获取图像并在单击下一个按钮时依次显示一个图像,它工作正常,除了它跳过一个图像并在它之后显示一个图像,我已经检查了 id在同一行中,id 也被跳过,所以我认为这是 mysql 连接器的问题。

方法示例:

public Pair<Integer,Image> image2()throws SQLException
{
int id;
System.out.println("I am in Image");

try {

System.out.println(rs);

boolean anyResults = false;

if (rs.next())
{

anyResults = true;

Blob blob = rs.getBlob("image");

id = rs.getInt("id");

System.out.println(id);
System.out.println(blob);
System.out.println(blob.length());


InputStream in = blob.getBinaryStream(1, blob.length());

System.out.println(rs.next());
System.out.println(in);

BufferedImage image = ImageIO.read(in);
System.out.println(image);

Image image1 = SwingFXUtils.toFXImage(image,null);


return new Pair<>(id, image1);

}
else if (!anyResults)
{
JOptionPane.showMessageDialog(null, "Not Found");
}


System.out.println("reached here");


} catch (Exception e)
{
e.printStackTrace();
}

return null;
}

下一个按钮的例子:

public void NextButtomClicked() throws SQLException
{
// this is what i used before => Image image1 = sql.image2();

//Pair<Integer, Image> image1 = sql.image2();

//Pair<Integer, Image> pair = sql.image2();
Pair<Integer, Image> pair = sql.image2();

Image image = pair.getValue();

list.add(pair.getKey());

this.imageView.setImage(image);

}

附言。 if(rs.Next) 的工作方式与 while(rs.Next) 相同

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com