This week's book giveaway is in the Go forum.
We're giving away four copies of Head First Go and have Jay McGavren on-line!
See this thread for details.
Win a copy of Head First Go this week in the Go forum!
  • 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Upload Image file to Oracle Database via JDBC from JSP  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I wanted to design a sample CRUD implemention including upload image. When I tried to insert information of Student involving in its id,name,surname,email address and image, these are inserted in the database except for image. I searched many suggestion on the Internet but nothing changed.

How can I insert image to the database?

Thank you.

Here is my code shown below. (Servlet,util class as controller and pojo meant for Student information)


util class




Student class







Ekran-Al-nt-s-1.PNG
[Thumbnail for Ekran-Al-nt-s-1.PNG]
 
Rancher
Posts: 3939
45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the JavaDoc for the available() method:

"Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream. "

That is not a count of the size of the stuff being streamed.

Use the setBinaryStream method that only takes two parameters.
 
Kevin Rapter
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:From the JavaDoc for the available() method:

"Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream. "

That is not a count of the size of the stuff being streamed.

Use the setBinaryStream method that only takes two parameters.



I used it before but nothing changed.

 
Ranch Hand
Posts: 277
2
Fedora Netbeans IDE Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You use the ioutil to get a byte array.  Is it because you read the stream one time so you arent getting any data?
 
Dave Tolls
Rancher
Posts: 3939
45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah!
Well spotted!

Yes, that's exactly what's happened (though the available method shouldn't be used anyway).

The image is already in the Student object as a byte[], and the stream has already been read, and hence empty.

It did occur to me that the odds of available returning 0 every time was a bit unlikely...

Anyway, so you either use the byte[], or ditch that and use the stream.
Personally I would stick with the stream.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!