/*Transaction tran = session.beginTransaction();
Connection connection = session.connection();
String sql = "INSERT INTO DomainBandwidth(domain_id,traffic,time) VALUES(?,?,?)";
PreparedStatement ps = null;
try {
ps = connection.prepareStatement(sql);
for (SnFlowDetailResult snFlowDetailResult : snFlowDetailResults){
boolean flag = false;
if (flag){
}else{
ps.setInt(1, domainId);
ps.setDouble(2, snFlowDetailResult.getTraffic());
ps.setTimestamp(3, new Timestamp(snFlowDetailResult.getTime()));
ps.addBatch();//添加到批次
}
}
ps.executeBatch();
tran.commit();
} catch (Exception e) {
tran.rollback();
log.error("", e);
}finally {
try {
ps.close();
connection.close();
session.close();
} catch (Exception e) {
log.error("", e);
}
}*/
//sql语句
// String updateSql = "UPDATE DomainBandwidth SET traffic = ? WHERE domain_id = ? and time = ?";
//通过session获取事务 和spring整合之后这步并不需要
// Transaction ts = session.beginTransaction();
/*session.doWork(
//实现work接口,work接口中有一个execute方法,connection就是这个方法的参数,也就是在这里获得jdbc的connection
new Work(){
@Override
public void execute(java.sql.Connection connection) throws SQLException {
try {
connection = session.connection();
PreparedStatement stmt = connection.prepareStatement(updateSql);
//这里进行批量操作
for (SnFlowDetailResult snFlowDetailResult : snFlowDetailResults){
stmt.setDouble(1, snFlowDetailResult.getTraffic());
stmt.setInt(2, domainId);
stmt.setTimestamp(3, new Timestamp(snFlowDetailResult.getTime()));
stmt.addBatch(); // 添加到批处理命令
}
stmt.executeBatch();
ts.commit();
} catch (Exception e) {
e.printStackTrace();
ts.rollback();
session.close();
}
}
});
session.close();*/
当当
https://blog.csdn.net/jinjiankang/article/details/78846518
https://gelei1014.iteye.com/blog/2095976
https://blog.csdn.net/zjt1388/article/details/52411901
http://www.imooc.com/article/277638
https://blog.csdn.net/yehuang_0801/article/details/78731122
https://www.cnblogs.com/codestory/p/5591651.html
https://blog.csdn.net/myshy025tiankong/article/details/83096720
http://www.manongjc.com/article/4243.html
https://blog.csdn.net/weixin_41704829/article/details/83023543