initial commit: lottery 项目集(三工程统一管理)
- apps/lotteryServer, lotteryCapture, lotteryOpen 三个业务工程 - 忽略 archive/, tools/, infra/data/ 大目录与敏感配置文件 - 移除 lotteryServer 原嵌套 git,并入顶层统一管理
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package javautils.jdbc.util;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class BatchSQLUtil {
|
||||
|
||||
public static Logger logger = LoggerFactory.getLogger(BatchSQLUtil.class);
|
||||
|
||||
private Connection conn;
|
||||
private PreparedStatement ps;
|
||||
|
||||
public BatchSQLUtil(Connection conn, String sql) {
|
||||
try {
|
||||
this.conn = conn;
|
||||
this.conn.setAutoCommit(false);
|
||||
ps = this.conn.prepareStatement(sql);
|
||||
} catch (Exception e) {
|
||||
logger.error("BatchSQLUtil异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void addCount(Object[] param) {
|
||||
try {
|
||||
for (int i = 0; i < param.length; i++) {
|
||||
ps.setObject(i + 1, param[i]);
|
||||
}
|
||||
ps.addBatch();
|
||||
} catch (SQLException e) {
|
||||
logger.error("addCount异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void commit() {
|
||||
try {
|
||||
ps.executeBatch();
|
||||
conn.commit();
|
||||
ps.clearBatch();
|
||||
} catch (SQLException e) {
|
||||
logger.error("commit异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
logger.error("close异常", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user