aspose file tools*
The moose likes JDBC and the fly likes source cod for selection and saving the pdf document 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 "source cod for selection and saving the pdf document" Watch "source cod for selection and saving the pdf document" New topic
Author

source cod for selection and saving the pdf document

Njk Naresh
Greenhorn

Joined: Nov 16, 2006
Posts: 11
source cod for selection and saving the pdf document into database.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

This question looks like it is something to do with a fish.

What are you asking? What are you stuck with?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Njk Naresh
Greenhorn

Joined: Nov 16, 2006
Posts: 11
Originally posted by Paul Sturrock:
This question looks like it is something to do with a fish.

What are you asking? What are you stuck with?


Hi, I want to store a pdf file in oracle database using jdbc code.
and how can we get the same document.(I am using BLOB datatype)but i am unable to get the results. i will share my code



import java.sql.*;
import java.io.*;

public class PDFConnect
{

public static void main(String args[])
{
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbcracle:thin:@10.81.7.169:1521:PTS", "TESTPTS", "TESTPTS");
System.out.println("connection established");
PreparedStatement ps = conn.prepareStatement("insert into DEMOBLOB values(?)");
System.out.println("insert executed");
File photo= new File("./sample.pdf");
System.out.println("image loaded ");
FileInputStream photostream= new FileInputStream(photo);
System.out.println("photo taken");
ps.setBinaryStream(1,photostream,(int)photo.length());
ps.executeUpdate();
photostream.close();

}

catch(Exception e)
{
}
}
}




The below code i had return for getting that pdf file.


import java.sql.*;
import java.io.*;

public class PhotoRetrive
{

public static void main(String args[])
{
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbcracle:thin:@10.81.7.169:1521:PTS", "TESTPTS", "TESTPTS");
System.out.println("connection established");

Statement sql_stmt = conn.createStatement();
System.out.println("got connection");
ResultSet rs = sql_stmt.executeQuery("select * FROM DEMOBLOB");
System.out.println("query executed");
rs.next();
InputStream in = rs.getBinaryStream("ephoto");

FileOutputStream fileout= new FileOutputStream("D:/MyOwn/");


int bytesRead = 0;
byte[] buffer = new byte[4096];

if(bytesRead == -1){
conn.close();
}else{
while(true){
bytesRead=in.read(buffer);
fileout.write(buffer,0,bytesRead);
fileout.close();
//System.out.println(rs.getString(1));
}
}
}
catch(Exception e)
{
}
}
}


know i am unable to get results no exceptions and no errors i want to know where iam doing the wrong.
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
Look back at the code you have written sure you aren't getting any exception because you wrapped your exception handling with "no-op". It's like crime in programming!!. If you print the exception you will get this


The line

doesn't have any filename where you want the PDF to be written.

And these lines

should be
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: source cod for selection and saving the pdf document