Link to home
Start Free TrialLog in
Avatar of Morfar3000
Morfar3000

asked on

How to store and get an image in Orcale

Could anybody give me a simple example about how to store a picture (fx jpg) in Oracle using Long Raw, and how to recieve it back. I'm using JSP. I have tried to store a picture (jpg), but i'm not sure that it works, because i'm not able to recieve it. here is the code for store-image:

<%@page language="java" import="java.sql.*, java.io.*, java.util.*"  %>

<%    
     
Connection conn = "connection is made here"
                   
File fil = new File("C:/testpicture.jpg");
FileInputStream fis = new FileInputStream(fil);
     
try {
               
  PreparedStatement ps = conn.prepareStatement("insert into Test values(?,?)");
                   
  ps.setString(1, "the name");
  ps.setBinaryStream(2, fis, 19000);
  ps.executeUpdate();
         
  ps.close();
  conn.close();
  fis.close();
         
  out.println("Success");

}      
     
catch(SQLException e ) {
  out.println(e);
}
         
%>

It seems to work, but i'm not sure. how do i recieve it back.

Avatar of shyamkumarreddy
shyamkumarreddy
Flag of United States of America image

Hi Morfar
Are you sure that u want to save it in long raw
if it is the case
In your insert statement Please use this function before inserting in the database as raw
insert into tables values(hextoraw(?),?)

Shyam

ASKER CERTIFIED SOLUTION
Avatar of naidubs
naidubs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Morfar3000
Morfar3000

ASKER

i'm using blob instead.

thx for the answer!!!!