我是苹果电脑 向 MySQL 数据库中插入中文数据时,中文变成"?"
publicvoidtestUpdate2()throwsException{try{JdbcUtils.beginTransaction();//开启事务Strings...
public void testUpdate2() throws Exception{
try {
JdbcUtils.beginTransaction();//开启事务
String sql = "insert into t_person(pName,pAge,sex) values(?,?,?)";
QueryRunner qr = new TxQueryRunner();
Object[] params = {"王朝","23","男"};
qr.update(sql, params);
if (false) {
throw new Exception();
}
params = new Object[]{"马汉","34","男"};
qr.update(sql, params);
JdbcUtils.commitTransaction();
System.out.println(params);
} catch (Exception e) {
// TODO: handle exception
try {
JdbcUtils.rollbackTransaction();//回滚事务
} catch (Exception e2) {
}
throw e;
}
} 展开
try {
JdbcUtils.beginTransaction();//开启事务
String sql = "insert into t_person(pName,pAge,sex) values(?,?,?)";
QueryRunner qr = new TxQueryRunner();
Object[] params = {"王朝","23","男"};
qr.update(sql, params);
if (false) {
throw new Exception();
}
params = new Object[]{"马汉","34","男"};
qr.update(sql, params);
JdbcUtils.commitTransaction();
System.out.println(params);
} catch (Exception e) {
// TODO: handle exception
try {
JdbcUtils.rollbackTransaction();//回滚事务
} catch (Exception e2) {
}
throw e;
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询