Jump to content
Changes to the Jaspersoft community edition download ×

postgresql bytea image problem


skuda

Recommended Posts

 Hi all,

    i am using iReport 4.0.0 and i am getting mad trying to load an image from Postgresql database, i have tried to use every nearly every possible combination of the field Class and expression Class of the image (java.io.InputStream in both, java.lang.String in both, java.lang.Object:java.awt.Image, etc....) but still does not works.

 

The same image works fine if i load directly with the local file in my filesystem, i have no problem to load images from blob types in Mysql but from Postgresql seems impossible, i have tried to encode the binary image file as base64 and load as java.lang.String from iReport but still the same result, i have tried too to use a old lob type object in Postgresql but it does not works either, so i am really lost with this problem.

 

I have searched in the forum and google to no avail but i can't find a solution to load directly from the database. Any help on this please?

 

Regards,

Miguel Angel.

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

  • 3 weeks later...

hi. i am working in postgresql. i want to disply image in iReport3.0. image which i have inserted in database is in bytea type. i have design ireport where i took

image-->

          properties-->

                       image -->

                                image expression ( $F{binarydata} which is byte data but class showing iava.awt.object)   -->

                                            image expression class ( i have selected iava.awt.image because there is no iava.awt.object set in image expression class as default).

  compilation done. but when i am trying to run i am getting following error.

Error filling print... Error evaluating expression :      Source text : $F{binarydata}
net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression :      Source text : $F{binarydata}     at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:197)     at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:537)     at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:505)     at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:826)     at net.sf.jasperreports.engine.fill.JRFillImage.evaluateImage(JRFillImage.java:890)     at net.sf.jasperreports.engine.fill.JRFillImage.evaluate(JRFillImage.java:871)     at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:275)     at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:426)     at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:1380)     at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:692)     at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:255)     at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:113)     at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:879)     at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:782)     at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:63)     at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:402)     at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:234)     at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:947)     at java.lang.Thread.run(Thread.java:595) Caused by: java.lang.ClassCastException: [b     at image_1298800067736_593298.evaluate(image_1298800067736_593298:170)     at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:186)     ... 18 more
Print was not filled. Try using an EmptyDataS

 

can anybody help me out?

 

Link to comment
Share on other sites

Hi,

    try using java.io.InputStream both on the result field of the query and in the image element in the report, if that does not works check that the jdbc driver you are using it is for the version of your Postgresql server or try with a Postgresql 9.0 JDBC driver.

Good luck.

Link to comment
Share on other sites

  • 3 years later...

i found a way to do this, but is not working at all, still working on it:

These are the step :

 

Create a Class with the next code :

import java.io.File;
import java.io.FileOutputStream;
import java.util.logging.Logger;

public class Images {

    private static final Logger log = Logger.getLogger("Images");

    public Images() {
    }

    public File convertBytes(java.io.InputStream objeto) {
        try {

            java.io.ByteArrayInputStream bais = (java.io.ByteArrayInputStream) objeto;
            String strBais = bais.toString();
            File file = new File("Foto.jpg");
            FileOutputStream fos = new FileOutputStream(file);
            int data;
            while ((data = bais.read()) != -1) {
                char ch = (char) data;
                fos.write(ch);
            }
            fos.flush();
            fos.close();
            return file;
        } catch (Exception e) {

            e.printStackTrace();
        }
        return null;
    }

 

2.- Add the image and Change the "Expression clase to java.io.File"

3.- In the "Image Expression" add new class.package.Image().convertBytes($F{FieldFromDatabase})

4.- Add the jar if needed and dont forget to add the imports on your properties report.

5.- Sometime is necesary to change the rigths where the image wil be allocated.

 

Link to comment
Share on other sites

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...