LongBlob图片未检索

时间:2019-04-23 18:58:28

标签: java mysql

我正在一个项目中,我必须从My Sql数据库中检索图像并将其显示在Swing JLabel中。

t下面的代码对于带有两列的另一个表是完美的,但是对于实际表,它并没有检索图像。为了进行测试,我将相同的图像存储在两个表中

   try {
       Class.forName("com.mysql.jdbc.Driver");
       connection1 = DriverManager.getConnection("jdbc:mysql://localhost:3306/beautysalon?" + "user=root&password=thiva");
       System.out.println("connected");
       int val = Integer.parseInt(jTextField1.getText());
       if (val  > 0) {
            ps1 = connection1.prepareStatement("select image from colour where id=?");
            // this below line is for image table (Just for testing) - working fine
            //   ps1 = connection1.prepareStatement("select * from image where id=?");
            ps1.setObject(1, val);
            rs3 = ps1.executeQuery();
            byte b[] = null;
            while (rs3.next()) {
                b = rs3.getBytes(2);
            }
            jLabel2.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(b)));
        } else {
            JOptionPane.showMessageDialog(this, "Please enter ID...");
        }
    } catch (Exception e) {
    }

0 个答案:

没有答案