• Post Reply Bookmark Topic Watch Topic
  • New Topic

invalid discriptor index error  RSS feed

 
Srinath R
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Her is a note on ResultSet getBinaryInputStream:
Note: All the data in the returned stream must be read prior to getting the value of any other column. The next call to a getXXX method implicitly closes the stream. Also, a stream may return 0 when the method InputStream.available is called whether there is data available or not.
Reverse the calls to the getXXX methods
int pdf_filesize=rs1.getInt("PDFFile_Size");
InputStream fileInput = rs1.getBinaryStream("PDF_File");
Hope this helps
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!