i am trying to retrieve an image field from the sql database useing the
jdbc useing FileInputStream and FileOutputStream i want to save it onto my hardisk for later use
given below is the code i have written
root = System.getProperty("server.root");
conn = dbHandle.getConnection();
pstmt = conn.prepareStatement("select PDF_File, PDFFile_Size from File_Info where File_Name = ?");
for(int i = 0; i < fileNames.size(); i++)
{
String fileNm = (String) fileNames.elementAt(i);
pstmt.setString(1,fileNm);
ResultSet rs1 = pstmt.executeQuery();
while(rs1.next())
{
InputStream fileInput = rs1.getBinaryStream("PDF_File");
int pdf_filesize=rs1.getInt("PDFFile_Size");
byte[] buffer = new byte[pdf_filesize];
String temp = root + "\\public_html\\Temporary";
File fl = new File(temp);
fl.mkdir();
FileOutputStream fileOutput = new FileOutputStream(temp + "\\" + fileNm + ".pdf");
try
{
fileInput.read(buffer);
}
catch(Exception e)
{
out.println(e);
}
fileOutput.write(buffer);
fileInput.close();
fileOutput.close();
}
rs1.close();
}
i traced out that the error is occuring at the statement
"fileInput.read(buffer);"
here PDF_File is the name of the field which is of the type image and fileNames is a vector which is containing some file names