wood burning stoves 2.0*
The moose likes JDBC and the fly likes Retreving PDF File from Database using Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Retreving PDF File from Database using Java" Watch "Retreving PDF File from Database using Java" New topic
Author

Retreving PDF File from Database using Java

Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 263
Dear Ranchers,

I am trying to insert a PDF file into the database and to retrieve it. I can insert the pdf successfully. Kindly send me the sample code for retreving the pdf file from the database.

Thanks/Regards

Aravind Prasad
Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 263
Sorry The code i am using is written below.


Please assist at the earliest.

Thanks/Regards
APrasad
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39549
    
  27
What is the problem with the code - doesn't it work?

You should close the FileOutputStream.


Ping & DNS - updated with new look and Ping home screen widget
Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 263
it is nt working.
it is creating a file with pdf extension but no data inside it.
Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 263
This is the complete code.
With this code, it is inserting the pdf in the database and also retreving. The file size which is inserting is same as file size retreving. But it is displaying only a blank pdf document. (meaning the pages are empty)

Please help

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39549
    
  27
You shouldn't ignore the result of the in.read call: http://faq.javaranch.com/java/ReadDoesntDoWhatYouThinkItDoes

Also, don't use a DataOutputStream - it's not meant for situations like this. Just use the FileOutputStream.
Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 263
Hi Thankyou.. my problem is solved.
The correct code is given below for others to refer.



Cheers!!!
Aravind Prasad
chandra reddy pandillapalle
Greenhorn

Joined: Mar 31, 2008
Posts: 6
if i am using the above code for uploading pdf file into databse it is giveing following error


java.sql.SQLException: Io exception: Char array not long enough: javaCharsToUtf8Bytes
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2061)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
at PDFFile.insertFile(PDFFile.java:46)
at PDFFile.main(PDFFile.java:79)
chandra reddy pandillapalle
Greenhorn

Joined: Mar 31, 2008
Posts: 6
please any one give reply what is the problem in that code
Thanks,
Chandra
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18140
    
    8

Did you use the same type of column that Aravind Prasad used?
[ March 31, 2008: Message edited by: Paul Clapham ]
Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 263
Reddy Bhai.

My table structure is given below. Please go thru this



This code will work perfectly. Also use longblob instead of Blob

Kindly update also

Regards
chandra reddy pandillapalle
Greenhorn

Joined: Mar 31, 2008
Posts: 6
this is my table structure i am also using same
CREATE TABLE IMAGE
(
IMG BLOB
)

please let me know why it is giving error
joseph okon
Ranch Hand

Joined: Dec 07, 2004
Posts: 63
Hi
Am using the same codes as above it is not giving me the required output that is it is not writing to the folder i want it to write to,
what can be wrong with my codes
please i need help
thanks

this is my code:





Perfection is for God only
Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 263
Hi Joseph,

Could you please kindly post your table structure also. Also the value you are passing thru request.getParameter().

Regards

Aravind
joseph okon
Ranch Hand

Joined: Dec 07, 2004
Posts: 63
Hi Joseph,
Could you please kindly post your table structure also. Also the value you are passing thru request.getParameter().
Regards
Aravind

this is my table structure:

mysql> show tables;
+-------------------+
| Tables_in_filesdb |
+-------------------+
| bigfiles |
| login |
+-------------------+
2 rows in set (0.06 sec)
mysql> desc bigfiles;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| file_id | varchar(15) | YES | | NULL | |
| file_img | longblob | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
2 rows in set (0.19 sec)
thanks for your assistance
Best regards
joseph
joseph okon
Ranch Hand

Joined: Dec 07, 2004
Posts: 63
Searchfile.jsp


Search.jsp code:

Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 263
Hoi Joseph

Try to modify the query you are using from


to



Also pass the parameter value as the file_id value.

Regards

Aravind Prasad
joseph okon
Ranch Hand

Joined: Dec 07, 2004
Posts: 63
Aravind Prasad
i have try the changes you made but it is still not doing it?? it produces null when run. i am short of idea can you write a piece of code to get parameter from html/jsp and retrieve the corresponding item from the database then place it in a folder for me? thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retreving PDF File from Database using Java
 
Similar Threads
Retreving from the MS Access database
Problem with retreving the Attribute in jsp
Retreving a file from MQ
Error shows while retreving data from database
Retreving data from Database and display on using JSTL.