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("jdbc:oracle: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("jdbc:oracle: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.