D
D
dgkotkovsky2016-12-09 12:18:23
Java
dgkotkovsky, 2016-12-09 12:18:23

What is the problem with Java transform converting blob to pdf?

There is a piece of Java code that should read a BLOB field from the table, which is an encoded PDF file. It is required to decode the blob and create a pdf file in the directory.
The code above creates a file, but it cannot be opened as a PDF.
Did by analogy with examples from the forums.
What could be the problem?
Thanks in advance.
BLOB is the name of the field passed from the previous transformation.
PSDevelopment is carried out in the Informatica PowerCenter ETL platform, so the code looks a bit strange.
8c6bc36e99714d72b09e8616042a83ea.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
aol-nnov, 2016-12-09
@aol-nnov

you need to start by checking that the blob contains a really valid pdf :)

E
exenza, 2016-12-09
@exenza

For me, it works like this:

Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:tcp://localhost:9092/~/Downloads/h2/mydb", "sa", "");
PreparedStatement ps = conn.prepareStatement("select PDF from FILES");
ResultSet rs = ps.executeQuery();

Blob blob = null;
if (rs.next()) blob = rs.getBlob("PDF");

if (blob != null) {
    File myPdf = new File("mypdf.pdf");
    ByteArrayInputStream is = new ByteArrayInputStream(blob.getBytes(0, (int) blob.length()));
    FileOutputStream fos = new FileOutputStream(myPdf);
    byte[] buf = new byte[is.available()];
    is.read(buf, 0, buf.length);
    fos.write(buf);
    is.close();
    fos.close();
}

as an option, debug your code from some thread of a human IDE, and then run it from Informatica (I'm not familiar with it, it looks like something ancient)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question