Jump to content

Regarding the blobs


vijay1440

Recommended Posts

Hi all! I have a small Application in which I need to insert an image into the Oracle 8i Database Blob Column and later I need to send that image to the Browser from a jsp.When the same code which i am putting below is executed in the stand alone programs, it is workig fine.But i am not getting the Image in the right format later due to which the Image is not opened.This is my code snippet in the stand-alone java file to insert the image.This same Image which is inserted with this prog is retrieved well with another stand alone java prog.And I am using a Type 4 jdbc driver*******************************Statement stmt = con.createStatement(); File file = new File("c:\\image1.gif"); FileInputStream fin = new FileInputStream(file); stmt.execute("INSERT INTO testimages VALUES(empty_blob())"); con.commit(); ResultSet rs = stmt.executeQuery("SELECT image FROM testimages FOR UPDATE"); while (rs.next()) { oracle.sql.BLOB blob = (oracle.sql.BLOB)rs.getBlob(1); OutputStream out = blob.getBinaryOutputStream(); int i; while ((i=fin.read())!=-1) { out.write((char)i); } out.close(); } con.commit();******************and my jsp code snippet isresponse.setContentType("multipart/form-data"); response.setHeader("Content-Disposition" , "attachment;fileName:image1.gif); java.sql.Statement stmt = con.createStatement(); java.sql.ResultSet rs = stmt.execteQuery("SELECT image FROM testimages"); while (rs.next()) { java.io.InputStream in = rs.getBinaryStream(1); int i; while ( (i=in.read()!=-1) { out.write((char)i); } } out.close(); %>Thanks a lot,VijayPlease solve my problem.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...