[resolved] Load pdf file into oracle database

Highlighted
One Star

[resolved] Load pdf file into oracle database

Hi,
Could somebody help me to load the pdf file to oracle DB. I have gone through few posts but didn't help. Kindly help me on this.
Note: My oracle table column data type is BLOB.
Thanks in advance,
Natarajan P

Accepted Solutions
Highlighted
One Star

Re: [resolved] Load pdf file into oracle database

I have resolved the problem. Here is the updated code- In case somebody else needed,
public static byte[] ByteArrayFromFile(String filePath) {
File file = new File(filePath);
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte;
try {
for (int readNum; (readNum = fis.read(buf)) != -1;) {
bos.write(buf, 0, readNum); //no doubt here is 0
System.out.println("read " + readNum + " bytes,");
}
} catch (IOException ex) {
System.out.println(ex);
}
byte[] bytes = bos.toByteArray();
return bytes;
}

View solution in original post


All Replies
Highlighted
Seventeen Stars

Re: [resolved] Load pdf file into oracle database

I am currently developing a tLOBUpload component. I guess it will be finished this weekend.
You can do your job with self written Java code. Establish a prepared statement and set a input stream.
For more details please refer the Java doc of the current JDBC API.
Highlighted
One Star

Re: [resolved] Load pdf file into oracle database

Thanks for your response. I have below JDBC prepared statement code to upload the file, But not sure where to place this code in tJDBCOutput component,
 File image = new File("C:\\FileUpload.pdf");  
psmnt = connection.prepareStatement("insert into FileUpload(name, city, image, Phone) "+ "values(?,?,?,?)");
psmnt.setString(1,"mahendra");
psmnt.setString(2,"Delhi");
psmnt.setString(4,"123456");
fis = new FileInputStream(image);
psmnt.setBinaryStream(3, (InputStream)fis, (int)(image.length()));
int s = psmnt.executeUpdate();

Kindly help.
Highlighted
One Star

Re: [resolved] Load pdf file into oracle database

I have resolved the problem. Here is the updated code- In case somebody else needed,
public static byte[] ByteArrayFromFile(String filePath) {
File file = new File(filePath);
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte;
try {
for (int readNum; (readNum = fis.read(buf)) != -1;) {
bos.write(buf, 0, readNum); //no doubt here is 0
System.out.println("read " + readNum + " bytes,");
}
} catch (IOException ex) {
System.out.println(ex);
}
byte[] bytes = bos.toByteArray();
return bytes;
}

View solution in original post

Highlighted
Seventeen Stars

Re: [resolved] Load pdf file into oracle database

well done!

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog