byte[]插入到MySQL数据库


//对象里面封装了byte[],把byte[]通过sql语句存入到MySQL数据库中
/**
* 插入一个对象到数据库中
*/
public boolean getInsertRSAAES(KeyBean kb) {
boolean flag = false;
//String sql = "INSERT INTO `t_key` (`sn`,`rsapublic`,`rsaprivate`,`aes`,`createtime`) VALUES ('"+kb.getSn()+"','@rsapublic','@rsaprivate','@aes','"+kb.getCreatetime()+"')";
try {
String sql = "INSERT INTO `t_key` (`sn`,`rsapublic`,`rsaprivate`,`aes`,`createtime`) VALUES (?,?,?,?,?)";
ps = conn.prepareStatement(sql);
ps.setString(1, kb.getSn());
ps.setBytes(2, kb.getRsapublic());
ps.setBytes(3, kb.getRsaprivate());
ps.setBytes(4, kb.getAes());
ps.setString(5, kb.getCreatetime());
int i = ps.executeUpdate();
if(i==1){
flag = true;
}
return flag;
} catch (SQLException e) {
System.out.println("执行SQL发生异常...");
e.printStackTrace();
}
return flag;
}

你可能感兴趣的:(MySQL)