• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

can anybody tell me how to upload a file(txt or doc or pdf)into database through java

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi to All,

I am praveen,can anybody help me in uploading a file through java.



with regards
praveen CH
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Use a PreparedStatement for your insert query.
2) Get an InputStream or Reader from the File
3) Use the PreparedStatement's most appropriate setXXX method.
4) executeUpdate() the PreparedStatement
5) close() the PreparedStatement
6) close() the InputStream or Reader from step 2

Words in capitals indicate the class to look for.
Words with () behind them indicate the method to use.

As for the most appropriate setXXX method, setAsciiStream or setCharacterStream are good options for character data (text files), whereas for DOC or PDF you'd want to store them in binary form, using setBinaryStream.
[ March 10, 2008: Message edited by: Rob Prime ]
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Praveen,

In addition to that you will have to define a column in your database table of type BLOB which will store the document in binary form.

Thanks,
Suraj
reply
    Bookmark Topic Watch Topic
  • New Topic