Jump to content
Changes to the Jaspersoft community edition download ×

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


siddhivinayak.sk

Recommended Posts

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

 

 

 

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...