• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Insert/Select Image from Oracle DB.  RSS feed

 
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
 
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..
 
I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!