为什么 rs.Next() 跳过列

why is rs.Next() skipping column

我一直在尝试构建一个 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);

    }

PS。 if(rs.Next) 与 while(rs.Next)

的工作方式相同

System.out.println(rs.next());跳行

尝试:

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

    try {

        System.out.println(rs);

        boolean anyResults = false;

        boolean hasNext = rs.next();


        if (hasNext )
        {

            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(hasNext );
            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;
}