This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

upload a file to dabase

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey can any one tell how i can upload a file from jsp and save it into database.And how will i know its saved in database.I am using sql server as database.
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

File upload is a task for servlets, not JSPs. See http://faq.javaranch.com/java/FileUpload for further information on Apache Commons FileUpload, a popular library that facilitates this.

File contents are best stored in a DB using a CLOB or BLOB field, depending on whether it's text or binary data. You might also want to read this thread on whether it's a good idea to store files in a DB.
 
siddharth paul
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry i didn't helped with the link. I need the code.
 
Ulf Dittmer
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I need the code.


And we'll help you write it, but we won't do it for you. Did you look at the FileUpload library? Its user guide has extensive explanations and example code.

As to saving to a database, are you familiar with JDBC? If not, you may to start reading here.
[ April 30, 2008: Message edited by: Ulf Dittmer ]
 
siddharth paul
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks.
i know jdbc connection and i have stored a file in sql server database. in the database field of file its written binary data,then how will i know its stored in database or not.
 
Ulf Dittmer
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you didn't get an exception while saving it's a good bet that it did get saved. You can always use SQLServer's tools to look at the DB directly to see what did get saved, or use JDBC to retrieve it and compare that with what you wanted to save.
 
siddharth paul
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot
its gud that i didn't got any exception.
Now can you help me how to retrive a file from database to local disk as like we download attachments from mail.
I mean what should i write in code like getBLOB() or anything else.
 
Ulf Dittmer
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. I think you can get an InputStream from the ResultSet that allows you to read the BLOB. You can then use regular file I/O to write its contents to disk.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic