This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Oracle/OAS and the fly likes How to store image file in Oracle 10g and how to retrieve it Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "How to store image file in Oracle 10g and how to retrieve it" Watch "How to store image file in Oracle 10g and how to retrieve it" New topic
Author

How to store image file in Oracle 10g and how to retrieve it

Rudra Nath
Greenhorn

Joined: May 12, 2012
Posts: 9
I wanted to store image from JAVA to Oracle 10 g .
I took following steps:
created a table with column type 'BINARY FILE LOB'.
My JAVA code is as follows for update:
String query = "update mytable set bfile_loc=bfilename(\'JPG_FILES\',\'"+myImg+"\') where name= \'" +frnd +"\'";
st.executeUpdate(query);

for fetching data from table I did as follows in resultSet:
while(rs.next()){
byte[] blobbytes = rs.getBytes("bfile_loc"); text = new String(blobbytes);
}
But I am getting follwing error:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:519)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:410)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause
javax.servlet.ServletException: java.sql.SQLException: ORA-22289: cannot perform FILEREAD operation on an unopened file or LOB

Please help.
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

As this is very Oracle-specific question, I'll move it to the Oracle forum.

First of all, I think you should use getBlob() to access the data in the file, not getBytes(). If that fails, I'd suggest to verify the following, though I'm not particularly experienced in this:

  • Does the JPG_FILES (case sensitive) directory alias exist?
  • Has the database user executing the query proper rights (READ) on this directory?
  • Does the file whose name is stored in myImg variable exist in that directory?
  • Haven't you exceeded the maximum number of open files in the session (SESSION_MAX_OPEN_FILES)?

  • Also, it would be better to use PrepraredStatement to prevent SQL Injection.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: How to store image file in Oracle 10g and how to retrieve it
     
    Similar Threads
    Storing large String in CLOB
    Hi, I'm intrying to upload a file into an ORACLE Database, but I got strange errors
    insert and retrieve image from database.
    how to store an image into the DataBase using oracle database
    Blob Clob