Answer the question
In order to leave comments, you need to log in
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.
Answer the question
In order to leave comments, you need to log in
you need to start by checking that the blob contains a really valid pdf :)
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();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question