• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

sample JSP code to upload file into database?

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey all,
please give me the sample JSP source code to upload file as object into database.

thanks,
rahul
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As a general rule, you don't want to have any JDBC code in a JSP. What you need to look at is:
  • How HTML forms handle files - for which you will need to use an form with the ENCTYPE set to "multipart/form-data"
  • How you handle the file parameter from this form - look at java.io.FileInputStream
  • You will also need to find out about CLOB or BLOB datatypes in the DB, which are how you store binary object in a relational database.
  • How JDBC handles CLOBS/BLOBS - look at java.sql.PreparedStatement's setClob(int i, Clob x) method.

  • Good luck. And please, post more quetions if you get stuck.
     
    Sheriff
    Posts: 13411
    Firefox Browser VI Editor Redhat
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    You'll also want to look into a library for handling your uploads.
    One like:
    http://jakarta.apache.org/commons/fileupload/
     
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    This is a crosspost with the servlet forum.
     
    Sheriff
    Posts: 67752
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Indeed it is. Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place.

    The other topic has been closed.
     
    Destiny's powerful hand has made the bed of my future. And this tiny ad:
    Smokeless wood heat with a rocket mass heater
    https://woodheat.net
    reply
      Bookmark Topic Watch Topic
    • New Topic