Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[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
Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

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

4 Replies
Anonymous
Not applicable
Author

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.
Anonymous
Not applicable
Author

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.
Anonymous
Not applicable
Author

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

Anonymous
Not applicable
Author

well done!