[resolved] Load pdf file into oracle database

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
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;
}


All Replies
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.
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.
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;
}

Seventeen Stars

Re: [resolved] Load pdf file into oracle database

well done!

2019 GARNER 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

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Agile Data lakes & Analytics

Accelerate your data lake projects with an agile approach

Watch