因为是blob数据,所以无法拼接sql,我记得jdbc给了一个方法,专门管这个事,但是具体哪个方法忘记了。。。
谁知道?
public void insertBlobData(){
Connection conn = null;
PreparedStatement ps = null;
String sql = "INSERT INTO customers(id, name, picture) VALUES(?,?,?)";
try{
conn = JDBCUtils.getConnection();
ps = conn.prepareStatement(sql);
ps.setInt(1, 12345);
ps.setString(2, "Alice");
InputStream in = new FileInputStream("test.jpg");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] b = new byte[1024];
int len;
while((len = in.read(b)) != -1){
baos.write(b, 0, len);
}
ps.setBytes(3, baos.toByteArray());
ps.executeUpdate();
in.close();
}catch(Exception e){
e.printStackTrace();
}finally{
JDBCUtils.release(conn, ps, null);
}
}
http://www.cnblogs.com/tengtao93/p/4984689.html
用 PerparedStatement,
看一下http://blog.csdn.net/ljheee/article/details/50988796