• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retreving PDF File from Database using Java

 
Aravind Prasad
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry The code i am using is written below.


Please assist at the earliest.

Thanks/Regards
APrasad
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the problem with the code - doesn't it work?

You should close the FileOutputStream.
 
Aravind Prasad
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is nt working.
it is creating a file with pdf extension but no data inside it.
 
Aravind Prasad
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Thankyou.. my problem is solved.
The correct code is given below for others to refer.



Cheers!!!
Aravind Prasad
 
chandra reddy pandillapalle
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please any one give reply what is the problem in that code
Thanks,
Chandra
 
Paul Clapham
Sheriff
Posts: 21153
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you use the same type of column that Aravind Prasad used?
[ March 31, 2008: Message edited by: Paul Clapham ]
 
Aravind Prasad
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Searchfile.jsp


Search.jsp code:

 
Aravind Prasad
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic