aspose file tools*
The moose likes JSP and the fly likes Problem in uploading image to to mysql database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem in uploading image to to mysql database" Watch "Problem in uploading image to to mysql database" New topic
Author

Problem in uploading image to to mysql database

Daryll sabate
Greenhorn

Joined: Apr 03, 2012
Posts: 7
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

Joined: Apr 03, 2012
Posts: 7
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

Joined: Jan 10, 2002
Posts: 61661
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Daryll sabate
Greenhorn

Joined: Apr 03, 2012
Posts: 7
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

Joined: Jan 10, 2002
Posts: 61661
    
  67

Have you moved the code out of the JSP and into a servlet?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18911
    
    8

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

Joined: Apr 03, 2012
Posts: 7
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

Joined: Jan 10, 2002
Posts: 61661
    
  67

Daryll sabate wrote:i put my code into servlet

Excellent!

what should be my next step?

Answer Pauls' questions.
Daryll sabate
Greenhorn

Joined: Apr 03, 2012
Posts: 7
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
Bartender

Joined: Oct 14, 2005
Posts: 18911
    
    8

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

Joined: Jul 05, 2008
Posts: 166

As Paul said use the Apache FileUpload package which is works fine for me.


No pain, No gain.
OCJP 1.6
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in uploading image to to mysql database