背景!jsp mysql 记住 要用mysql的longblob类型来存默认的blob大小不够
转载请注明出处,这时我与我的知己的合作的结过
原来操作blob字段时都要先差个空值,在查blob,好麻烦,用prepareStatment就不用那么麻烦了,哈哈
postblob.heml页面
ttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" snap_icon_added="spa" icon_trigger="false" text_trigger="true" parent_link_icon="false" snap_preview_added="spa">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">
无标题文档
id
file
***************************************************************
testblob.jsp
http://www.w3.org/1999/xhtml">
无标题文档
String id=request.getParameter("id");
String file=request.getParameter("file");
out.print(id);
out.print(file);
FileInputStream str=new FileInputStream(file);
out.print(str.available());
java.sql.Connection conn;
java.lang.String strConn;
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn= java.sql.DriverManager.getConnection("jdbc:mysql://localhost/test","root","");
String sql="insert into test(id,pic) values(?,?)";
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1,id);
pstmt.setBinaryStream(2,str,str.available());
pstmt.execute();
out.println("Success,You Have Insert an Image Successfully");
pstmt.close();
%>
查看图片
返回
********************************************************
readblob.jsp