mysql支不支持binary型的,如何用blob存取图片,能给出实例代码吗?大哥们给出一些实例呗Connectionconn=null;try{Class.forName("com.mysql.jdbc.Driver");conn=DriverManager.getCo...
mysql支不支持binary型的,如何用blob存取图片,能给出实例代码吗? 大哥们给出一些实例呗
Connection conn=null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/photo","root","root");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
String id=request.getParameter("id");
String fileName=request.getParameter("image");
FileInputStream str=new FileInputStream(fileName);
String sql="insert into photo(id,photo)values(?,?)";
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1,id);
pstmt.setBlob(2,str,str.available());
pstmt.execute();
pstmt.close();
out.println("恭喜,已经将新的数据库添加到数据库中");你们看看这段代码有错误吗
展开