通过 jdk 自带的 rt 包中 javax 的类 SerialBlob 保存到数据库。
代码:
byte[] bytes ="".getBytes()
SerialBlob serialBlob = new SerialBlob(bytes);
updateSQL("update table set name = ? where ACCOUNT= ?",new Object[]{serialBlob,"用户名"});
public void updateSQL(String sql,Object[] objects) {
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try {
con = DbUtil.getConnection();
con.setAutoCommit(false);
pstm = con.prepareStatement(sql);
if (objects != null) {
for (int i = 0; i < objects.length; i++) {
pstm.setObject(i+1,objects[i]);
}
}
pstm.executeUpdate();
con.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
DbUtil.close(con, pstm, rs);
}
}