• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

invalid discriptor index error

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic