• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sample JSP code to upload file into database?

 
rahul saxena
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey all,
please give me the sample JSP source code to upload file as object into database.

thanks,
rahul
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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.
     
    Ben Souther
    Sheriff
    Posts: 13411
    Firefox Browser Redhat VI Editor
    • Mark post as helpful
    • send pies
    • 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/
     
    Ben Keeping
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    This is a crosspost with the servlet forum.
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 65342
    97
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • 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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic