• 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
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

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: 67645
    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.
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic