wood burning stoves*
The moose likes JDBC and the fly likes Upload file and store it in database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Upload file and store it in database" Watch "Upload file and store it in database" New topic
Author

Upload file and store it in database

Sri Gnana
Ranch Hand

Joined: Apr 29, 2004
Posts: 166
Hi,
Now i'm able to upload the file and store it in server, but i wanna store it in database, please give me an idea and url for reference.


Thanks & Regards
Sri Gnana
Everythings Programmed!...
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Have a look at the interfaces java.sql.Clob and java.sql.Blob, then have a look at the setBinaryStream(int parameterIndex, InputStream x, int length) method of java.sql.PreparedStatement class. You should be able to work it out from there.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

Moving to the JDBC forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sri GS
Greenhorn

Joined: Apr 29, 2004
Posts: 3
Thanks
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
There are 2 ways to do that

1 - Store the path of the file in Database and then display the image using that path. It will be efficient and your database size will reasonably reduce.
2 - Store the actual image in database in the form of bytes and then read those bytes and make a file and then display that in your page. This technique is more reliable as compare to 1st because if path of the files changes or any file get deleted then there will raise problems.

Its all depends on your requirements.
 
 
subject: Upload file and store it in database
 
Similar Threads
File object
how to upload file along with HTML form data
Upload attachment using Java
How to store/retrive images from database
Using commons-fileupload-1.2.1.jar to upload file to MySQL