aspose file tools*
The moose likes Servlets and the fly likes Problem Uploading Image to DB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem Uploading Image to DB" Watch "Problem Uploading Image to DB" New topic
Author

Problem Uploading Image to DB

Gaurav Wadhwani
Ranch Hand

Joined: Sep 21, 2010
Posts: 68
Using MS Access as DB

Image attribute in Itable is OLE object

The following Servlet shows FileNotFound Exception. Even though the file is present.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I've edited your code to remove irrelevant details.

Please note: there is only one instance of a servlet created for each servlet mapping: your connection is being shared by *every* request that comes in; unless you can *guarantee* that only one person will *ever* use the application, you're heading towards a world of debugging pain. Servlets *must* be thread-safe. Also note that not closing the connection will cause serious issues as well.

Where does the error actually occur? If it says the file isn't there, it likely isn't there, or you don't have access to read it.
Gaurav Wadhwani
Ranch Hand

Joined: Sep 21, 2010
Posts: 68

Thank you for the reply.
Ok so there are two issues now. Since im making these small codes and will later compile them all to make a big Web application.

1. How do i make it thread safe? So that every user that comes in gets his own DB connection. As there will be multiple users accessing the same servlet at the same time.

2. The file exists and i have the permissions to access it.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Gaurav Wadhwani wrote:1. How do i make it thread safe? So that every user that comes in gets his own DB connection. As there will be multiple users accessing the same servlet at the same time.

Don't use instance variables for the connection. I don't know if the prepared statement can be an instance variable or not.

Normally an application of any size would use some sort of connection pooling, but it really depends on how much traffic you're expecting whether or not it's worth bothering.
2. The file exists and i have the permissions to access it.

I'm a little skeptical, since Java believes otherwise. And it doesn't matter if *you* have permissions--it only matters if the app server has permissions.
Gaurav Wadhwani
Ranch Hand

Joined: Sep 21, 2010
Posts: 68
I didnt understand this. And im expecting only 5 users max for my web application.

Don't use instance variables for the connection. I don't know if the prepared statement can be an instance variable or not.

Normally an application of any size would use some sort of connection pooling, but it really depends on how much traffic you're expecting whether or not it's worth bothering.



I dont know how to set permission for a File IO in glassfish. However, since i saw most of the websites for this tutorial, none had mentioned about permissions, so i guessed it already has.
 
wood burning stoves
 
subject: Problem Uploading Image to DB