aspose file tools*
The moose likes JDBC and the fly likes can anybody tell me how to upload a file(txt or doc or pdf)into database through java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "can anybody tell me how to upload a file(txt or doc or pdf)into database through java" Watch "can anybody tell me how to upload a file(txt or doc or pdf)into database through java" New topic
Author

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

ch praveen kumar
Greenhorn

Joined: Jul 30, 2007
Posts: 21
Hi to All,

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



with regards
praveen CH
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19722
    
  20

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 ]

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Suraj Berwal
Greenhorn

Joined: Dec 28, 2001
Posts: 26
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
 
subject: can anybody tell me how to upload a file(txt or doc or pdf)into database through java