public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
DataBase db = new DataBase();
Connection con=null;
String mobileid=request.getParameter("mobileid");
try {
con = db.getConnection();
} catch (SQLException e) {
// TODO 锟皆讹拷锟斤拷锟?catch 锟斤拷
e.printStackTrace();
}
byte a[]=null;//字节码
java.io.FileInputStream fin=null;
InputStream in =null;
oracle.jdbc.OracleResultSet ors=null;//这个非常重要
oracle.jdbc.driver.OraclePreparedStatement opst=null;
try {
con.setAutoCommit(false);
} catch (SQLException e) {
e.printStackTrace();
}
try {
String mysql="select picture from bs_mobile where mobileid=?";
//根据图片的ID查询图片
opst=(oracle.jdbc.driver.OraclePreparedStatement)con.prepareStatement(mysql);
opst.setString(1,mobileid);
ors=(oracle.jdbc.OracleResultSet)opst.executeQuery();
if (ors.next())
{
oracle.sql.BLOB blob2=ors.getBLOB(1);
in = ors.getBinaryStream(1);
//System.out.println("blob2 length:"+blob2.length());
int lth= (int) blob2.length();
response.reset();
response.setContentType("image/jpg");
con.commit();
OutputStream toClient = response.getOutputStream();
byte[] P_Buf = new byte[lth];
int i;
while ((i = in.read(P_Buf)) != -1) {
toClient.write(P_Buf, 0, i);
}
in.close();
toClient.flush();
toClient.close();
}
} catch (SQLException e) {
e.printStackTrace();
}catch(NullPointerException npe){
}