try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(
"jdbc:oracle:thin:@IpAddress:1521:orcl1",
"user","pwd");
/*File monImagel = new File("E:\\JDevloper\\jdev\\mywork\\JcWebAppli\\JcDataBase\\public_html/events.xml");
FileOutputStream ostreamImage = new FileOutputStream(monImagel);*/
try
{
PreparedStatement pss = con.prepareStatement("select xmlfile from latestevents where id_event=?");
try
{
pss.setInt(1,3);
ResultSet rss = pss.executeQuery();
rss.next();
Blob blob = rss.getBlob("xmlfile");
try
{
InputStream istreamImagel = blob.getBinaryStream();
//response.reset();
byte[] buffer = new byte[1024];
int length = 0;
while(((length = istreamImagel.read(buffer)) != -1))
{
//ostreamImage.write(buffer, 0, length);
response.getOutputStream().write(buffer,0,length);
}
response.flushBuffer();
}
catch(Exception e)
{
out.println("ERROR1: "+e);
}
finally
{
rss.close();
}
}
catch(Exception e)
{
out.println("ERROR2: "+e);
}
finally
{
pss.close();
}
}
catch(Exception e)
{
out.println("ERROR3: "+e);
}
finally
{
//ostreamImage.close();
}
}
catch(ClassNotFoundException e)
{
out.println("<p>Could not load database driver:"
+e.getMessage()+"</p>");
}
catch(SQLException e)
{
out.println("<p>SQLException caught:"
+e.getMessage()+"</p>");
}
finally
{//close connection no matter what
try
{
if(con!=null)
{
con.close();
}
}catch(SQLException ignored){}
}
Partager