java读取oracle中blob字段

Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();   
String URL=dbmes.url;   
Connection con = DriverManager.getConnection(URL,dbmes.usrname,dbmes.pwd);   
try{   
// 准备语句执行对象   
String bh=request.getParameter("dwmc");   
  
Statement stmt = con.createStatement();   
String sql = "select tp1 from HJ_ZDQY_TAB where dwmc='"+bh+"'";   
    
ResultSet rs = stmt.executeQuery(sql);   
if (rs.next()) {   
  Blob tp1 = rs.getBlob("tp1");   
  long size1 = tp1.length();   
  if(size1<=0){   
   rs.close();   
   response.sendRedirect("../images/error.jpg");   
  }else{   
   byte[] bs1 = tp1.getBytes(1, (int)size1);   
   response.setContentType("image/jpeg");    
   response.getOutputStream().write(bs1);    
   rs.close();   
  }   
}else {   
  rs.close();   
  response.sendRedirect("../images/error.gif");   
}   
}   
finally{   
     
con.close();   
}   
     out.clear();   
  out=pageContext.pushBody();   

你可能感兴趣的:(java,oracle,sql,jdbc)