JAVA - Can't Fetch Image in database (mysql)
<p>Back then, I successfully manipulated my webcam through webcam-capture library.
Here is my code :</p>

<pre><code>public void capture() {
    wc.setViewSize(WebcamResolution.QVGA.getSize());
    WebcamPanel wp = new WebcamPanel(wc);
    wp.setMirrored(true);
    JPanel jp = new JPanel();
    tp.setSize(jp.getWidth(), jp.getHeight());
    tp.addTab("", wp);
    tp.getParent().revalidate();
}
</code></pre>

<p>And it happen that I want to save the capture image into my database (mysql),
the good thing is that I able to save it successfully.
With this codes:</p>

<pre><code>public void save() {
    BufferedImage bi = wc.getImage();
    try {
        ByteArrayOutputStream bimg = new ByteArrayOutputStream();
        ImageIO.write(bi, "JPG", bimg);
        byte[] imgb = bimg.toByteArray();

        try {
            Blob bis = conn.createBlob();
            bis.setBytes(1, imgb);
            String query = "insert into tbl_img (imgid,clientimg) values ('" + but.getText() + "' , '" + bis + "')";
            psmt = conn.prepareStatement(query);
            psmt.executeUpdate();
            JOptionPane.showMessageDialog(null, "Success", "Capture", JOptionPane.NO_OPTION);

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

    } catch (IOException e) {
        JOptionPane.showMessageDialog(null, e);
    }
}
</code></pre>

<p>From BufferedImage I converted it ByteArray to fit into the mysql Blob flag.
As oppose of  inserting data, I want to retrieve it back as image and put it in the JLabel through JFrame directly. Shall we say without occupying some space in the Hard Drive.</p>

<p>I have a code for retrieving image but the result seems a white JFrame only.</p>

<pre><code>public void open() {
    try {
        stmt = conn.createStatement();
        String quer = " select clientimg from tbl_img where imgid='" + open.getText() + "' ";
        ResultSet rs = stmt.executeQuery(quer);
        while (rs.next()) {
            byte[] inbytes = rs.getBytes("clientimg");
            Image img = Toolkit.getDefaultToolkit().createImage(inbytes);
            ImageIcon ico = new ImageIcon(img);
            JFrame jf = new JFrame("Viewer");
            JLabel jl = new JLabel();
            jl.setSize(ico.getIconWidth(), ico.getIconHeight());
            jf.setSize(ico.getIconWidth(), ico.getIconHeight());
            jl.setIcon(ico);
            jf.add(jl);
            jf.setVisible(true);

        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}
</code></pre>

<p>Is there another way or retrieving blob back to image ? if there is feel free to modify the code for me to make it clearer to understand. I have tried I think all of possible way from google.</p>