How to create blob objects
1 posts in topic
Flat View  Flat View

Posted By:   Christophe_Grosjean
Posted On:   Tuesday, February 19, 2002 01:14 AM

Hi all,
I want to create Blob objects. How can i do that ? Must I implement the java.sql.blob interface ? I did it for Clob object but internal representation of a blob seems to be more complex... what could be this implementation of a blob ?

Thx for any help.

Re: How to create blob objects

Posted By:   thirupathi_rajan  
Posted On:   Wednesday, February 20, 2002 01:18 AM

Actualy, i have done storing & retrieving .gif images into database. when i am retrieving images from database, i used blob. For this, i imported java.sql.blob. i am sending samle codes for ur reference. Are u trying to store and retrieve images into database......?.

To store a image,

Connection conn=null;


File image = new File("c:\images\adobe.gif");

InputStream streamimage = new FileInputStream(image);

conn = getConnection();

PreparedStatement pstmt = conn.prepareStatement("insert into image ( imageid, imageblob ) values ( ?, ?) ");

pstmt.setString(1, "101");

pstmt.setBinaryStream(2, streamimage, ( (int) image.length() ) );

When retrieving image,

Connection conn=null;

Blob blob=null;

int blength;

byte [] imgBytes = "sd".getBytes();

conn = getConnection();

Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery ("select * from image");


blob = rs.getBlob("imageblob");

blength = (int)(blob.length());

imgBytes = blob.getBytes(1, blength);

In the database, datatype of imageblob variable should be "blob".
I hope that it should be helpful for u.
About | Sitemap | Contact