Click here to Skip to main content
16,004,647 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to store the images, pdf, videos into Oracle database. I need to use JPA and JPQL to do this.
There is @Lob annotation in JPA for Lob. but i dont know how to insert them into the table. somebody help me on it.

Thanks...
Posted

JPA - Introduction to the Java Persistence API[^]

JPQL - The Java Persistence Query Language[^]

I strongly recommend a book for that: Pro JPA 2: Mastering the Java Persistence API (Expert's Voice in Java Technology)[^]

and make yourself some test and evaluation project, so you can play around without any further need to be productive on that.
 
Share this answer
 
Comments
kalai91 28-Mar-12 6:22am    
Thanks for your solution. I read all those documents. But still I did not know how to insert and retrieve.
After reading those, I came to know that annotation @Lob should be used for byte array type to store image.
@Lob
private byte[] picture;


I used this method to convert image file to bytes,
public static byte[] writingImage(String fileLocation) {
byte b[] = null;
try {
FileInputStream fis=new FileInputStream(new File(fileLocation));
fis.read(b);
return b;
} catch (IOException e) {
}
return null;
}

For setting value for the above picture variable, i did this.,
void setPicture(byte[] picture)
{
this.picture=picture;
}

In main method,
objectname.setPicture(writingImage("c:\img\image.jpg"));

In main method I did this, and persisted it.
I dont know whether that is the right way. Also dont know how to retrieve it back.

How to do that actually??
WajihaAhmed 30-Mar-12 7:41am    
+1 for book Pro JPA. kalai91 , please let me know what you finally did, as I will be starting this work after some days
I am also working on a project where I will be diong exactly the same stuff and really confused. But I read some where that its better to store all the pictures, vedios etc in a folder on server and add a link of that file in database to acheive good performance.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900