File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
ch praveen kumar
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Rob Spoor
Sheriff
Pie
Posts: 20380
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Suraj Berwal
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic