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

Problem in uploading image to to mysql database

 
Daryll sabate
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
  • 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


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you moved the code out of the JSP and into a servlet?
 
Paul Clapham
Sheriff
Pie
Posts: 20772
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Pie
Posts: 20772
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
Kumaravadivel Subramani
Ranch Hand
Posts: 171
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Paul said use the Apache FileUpload package which is works fine for me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic