File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and the fly likes How to set and get images in Oracle databse   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 » Databases » JDBC
Bookmark "How to set and get images in Oracle databse   " Watch "How to set and get images in Oracle databse   " New topic

How to set and get images in Oracle databse

Manish Tiwari

Joined: May 19, 2004
Posts: 5
Friends here is my code it runs succesfully but when i try to see the image
stored in the file it gives me windows error saying bmp is not a valid file .
can i get the code for saving and retriving the image in BLOB column of database .
PLZ help .
package test;
import java.sql.*;
public class GetImage
public static void main(String args[])
Blob blob = null;
Connection1DB cdb = new Connection1DB();
Connection conn = (Connection)(cdb.getConnection());
System.out.println("Got the connection");
FileOutputStream fos= new FileOutputStream("E:/javatest/dbimage.bmp");
String sql1= "select IMAGE1 from IMAGE ";
Statement stmts = conn.createStatement();
ResultSet rs = stmts.executeQuery(sql1);
InputStream ims=null;

long len= blob.length();
byte collect[]= blob.getBytes(1l,(int)len);
System.out.println(""+ collect);
catch(Exception e)



I agree. Here's the link:
subject: How to set and get images in Oracle databse
Similar Threads
getblob from db, then convert to byte and write to bitmap/jpeg
problem in getting Blob data and displaying
write pdf files whith servlets
Retreving PDF File from Database using Java
Writing as a JPG file to disk