• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem in uploading image to to mysql database

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, need some help here, i have a program where a user can input name, city and upload image. when a user click the submit button the name, city and the image(Save as BLOB) must be save in the database. and the image will also save in the desired folder. i have no problem in saving the image in the folder, my problem is it can't save the record to mysql database.

heres my code...

index.jsp



upload.jsp

 
Daryll sabate
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
O.T

but when i try to input the record manually to the code like this it will successfully save... see difference in line 53-54(code at the top) from 51-52(here) and i remove some code in line 39-40


 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is the upload code in a JSP and not a servlet?

Step1: Change the forma action to submit to a servlet into which you move the upload code.
 
Daryll sabate
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank for replying sir, but can you give me a hint.. like some code to follow.. thanks in advance
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you moved the code out of the JSP and into a servlet?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what are the symptoms of your problem? It appears from what you wrote that the record is not being written to the database, but that isn't very helpful. Especially when you have debugging code in place already, which you aren't telling us about.
 
Daryll sabate
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear Bibeault,

i put my code into servlet,

upload.jsp to upload.java



can you please check if its correct, and after this, what should be my next step?

thanks sir
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Daryll sabate wrote:i put my code into servlet


Excellent!

what should be my next step?


Answer Pauls' questions.
 
Daryll sabate
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually my from now i can upload the image and it successfully save in my database, my problem is, i can't save the text input to my database.. it always appear NULL.

so it means the my STRING Name = request.getParameter("name") is not working..

my question is, how can i saved this text input to my database, is it ok if try to use another connection just to get the value of the text input.?

all i want from now is to save that text input to my database.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To me it looks like you're processing a multipart request with that code. I've done that, but I never considered trying to parse the request myself. Instead, I used the Apache FileUpload package which works just fine and I don't have to hack around with boundaries or any of that. And it can store the file upload in a temporary file if you ask it to do so.

Anyway, one feature of multipart request is that what you think of as "parameters" (i.e. the HTML form fields which aren't file uploads) are not treated as request parameters. One of your code samples appeared to be assuming that they were. But they aren't. They are just another "part" of the request (or maybe one part per parameter, I don't know) so you're going to have to extract them from the request in just the same way as you extracted the file upload.
 
Ranch Hand
Posts: 171
Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Paul said use the Apache FileUpload package which is works fine for me.
reply
    Bookmark Topic Watch Topic
  • New Topic