aspose file tools*
The moose likes JDBC and the fly likes Insert/Select Image from Oracle DB. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Insert/Select Image from Oracle DB." Watch "Insert/Select Image from Oracle DB." New topic
Author

Insert/Select Image from Oracle DB.

Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
hi,

Please provide some sample code for inserting and selecting image of size 500 kb into/from oracle.

and what should be the data type in oracle for it.

Regards,
Neeraj
Dave Salter
Ranch Hand

Joined: Jul 20, 2005
Posts: 292

Hi,

If you search this forum for the words "Oracle" and "Blob", you should find your answers.

Cheers,

Dave.
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
Hi,

Thnx dave.. I got some info with the search...

I am able to fetch and insert images into oracle..only if the gif image size is 1 kb.. more than that give null poiter exception..

any inputs will be a great help..

Regards,
Neeraj.
Dave Salter
Ranch Hand

Joined: Jul 20, 2005
Posts: 292

Can you show us the code you are using. Also, is there a stack trace of any exceptions?

Cheers
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
ResultSet rs = st2.executeQuery("Select picture from neeraj_pic_store where description='1'");
while (rs.next()){
blob=((OracleResultSet)rs).getBLOB(1);
is1=blob.getBinaryStream();
}

int pos=0;
int length=0;
byte[] b = new byte[blob.getChunkSize()];

while((length=is.read(b))!= -1){
pos+=length;
os.write(b);
}
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
tried this also

ResultSet rs = st2.executeQuery("Select picture from neeraj_pic_store where description='1'");
BufferedInputStream bis=null;
if ((rs.next()))
{

bis = new BufferedInputStream( rs.getBinaryStream("picture") );
byte bindata[] = new byte[1024];
int bytesread = 0;
while ( (bytesread = bis.read(bindata,0,bindata.length)) != -1 )
{
os.write(bindata);
}



}

getting stream closed exceptionm..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Insert/Select Image from Oracle DB.