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("ins ert 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.
<%@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("ins
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i'm using blob instead.
thx for the answer!!!!
thx for the answer!!!!
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