Java code
if (MultipartFormDataRequest.isMultipartFormData(request)) {
MultipartFormDataRequest mrequest = new MultipartFormDataRequest(request);
Hashtable files = mrequest.getFiles();
if ((files != null) || (!files.isEmpty())) {
UploadFile file = (UploadFile) files.get("uploadfile");
String file_name = file.getFileName();
PreparedStatement pstmt=con.prepareStatement("insert into blobtest values(1,?)");
FileInputStream fis = new FileInputStream(file.getInpuStream());
//把输入流设置为预处理语句的对象。
pstmt.setBinaryStream(1, fis, (int)file.length());
//执行更新
pstmt.executeUpdate();
pstmt.close();
}
}
------解决方案--------------------
Connection con=null;
Statement stmt=null;
try{
con=sqlConn.getConnection();
stmt=con.createStatement();//数据库的连接
String sql="select * from dd_model WHERE model_no='07002'";
ResultSet rs=stmt.executeQuery(sql);
rs.next();
InputStream in=rs.getBinaryStream("shoe_pic");
response.reset();
response.setContentType("image/jpeg");
byte[] b=new byte[1024];
int len;
while((len=in.read(b))>0)
{
response.getOutputStream().write(b,0,len);
}
out.clear();
out = pageContext.pushBody();
in.close();
rs.close();
stmt.close();
con.close();