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
1 ACCEPTED SOLUTION

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

4 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!