java向MYSQL中插入图片时为列属性为LONGBLOB,抛出异常?
java向MYSQL中插入图片时为列属性为LONGBLOB,抛出异常?大侠们帮帮忙。谢谢了!
代码如下:
public void blobInsert(String infile,int id) throws Exception
{
FileInputStream fis = null;
try
{
fis = new FileInputStream(infile);
String sql = "insert into t_photo values(?,?,?)";
PreparedStatement pstmt = ConnPool.request().getPreStmt(sql);
System.out.println(pstmt.toString());
pstmt.setInt(1, id);
pstmt.setString(2,infile); //把传过来的第二个参数设为文件名
pstmt.setBinaryStream(3,fis,fis.available()); //第三个参数为文件的内容
System.out.println(fis.available());
pstmt.executeUpdate();
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
fis.close();
}
}