Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

source cod for selection and saving the pdf document

 
Njk Naresh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
source cod for selection and saving the pdf document into database.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question looks like it is something to do with a fish.

What are you asking? What are you stuck with?
 
Njk Naresh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic