为什么rs.next()跳过列

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

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

两年前关门了。
改进这个问题
我一直在尝试建立一个图形用户界面,从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)相同

dtcbnfnu

dtcbnfnu1#

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;
}

相关问题