Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Insert/Select Image from Oracle DB.

 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 293
Java Mac OS X Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

Cheers,

Dave.
 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 293
Java Mac OS X Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us the code you are using. Also, is there a stack trace of any exceptions?

Cheers
 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic