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

0

Hi,

I'm trying to test Jasper report with Derby 10.14.2.0 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

$F{A_SIGN_IC1}.getBinaryStream()

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.

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

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

 

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.

 

Regards,

Sandeep

 

 

 

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

0 Answers:

No answers yet
Feedback