File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases 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 and Relational Databases
Bookmark "Upload file and store it in database" Watch "Upload file and store it in database" New topic

Upload file and store it in database

Sri Gnana
Ranch Hand

Joined: Apr 29, 2004
Posts: 166
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

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

Joined: Jan 10, 2002
Posts: 63858

Moving to the JDBC forum.

[Asking smart questions] [About Bear] [Books by Bear]
Sri GS

Joined: Apr 29, 2004
Posts: 3
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.
I agree. Here's the link:
subject: Upload file and store it in database
It's not a secret anymore!