Jasper Report with Derby with java.sql.Blob as Image



I'm trying to test Jasper report with Derby database with image saved as java.sql.Blob.

I tried many times with different approches to load the image from the database (using expression) like,

//Getting java.awt.Image

new javax.swing.ImageIcon($F{A_SIGN_IC1}.getBytes(1, (int)$F{A_SIGN_IC1}.length())).getImage()

//Getting InputStream


Each time getting error.

Then tried to check the size of the Blob object by using $F{A_SIGN_IC1}.length(), it results 3.


Though, I tried to render image by writing separate Java program, it is working with below code.

        Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/sample", "user", "app");

        JFrame jf1 = new JFrame("Test");
        jf1.setSize(400, 400);
        JButton jb = new JButton("");
        jb.setSize(200, 300);
        PreparedStatement ps2 = con.prepareStatement("***");
        ResultSet rs = ps2.executeQuery();
        int z = 0;
        while(rs.next()) {
            Blob bl1 = rs.getBlob(1);
            ImageIcon ii = new ImageIcon(bl1.getBytes(1, (int)bl1.length()));
            java.awt.Image img = ii.getImage();


I'm not sure about the issue what is happening. Because if image is being rendered using separate Java program from the database that simply means image is stored correctly. It seems there is an issue with Jasper Only.


Please help.







siddhivinayak.sk's picture
Joined: Jan 6 2019 - 8:56pm
Last seen: 1 month 4 weeks ago

0 Answers:

No answers yet