public void testStatementAddBatch() public void testConnCommit()



public void testStatementAddBatch()
{
Connection conn = null;
Statement stmt = null;
try
{
conn = getDBConnectionMsSqlBySuperAdmin();
stmt = conn.createStatement();
for(int i = 0; i < 100; i++)
{
String sql = " sql " + i;
stmt.addBatch(sql);
}
stmt.executeBatch();
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{

}
}

// private boolean insertIntoSpecialDataTableFromList(List insertSqlList, String[] cts, PreparedStatement pstmt, Connection connection)
// {
// boolean isExecuteCorrect = false;
// try
// {
// for(int i = 3; i < insertSqlList.size(); i++)
// {
// String recorder = (String)insertSqlList.get(i);
// String[] rs = recorder.split(ResBackupUtil.SPLIT_TAG);
// for(int k = 0; k < rs.length; k++)
// {
// setObject(pstmt, k + 1, cts[k], rs[k]);
// }
// pstmt.addBatch();
// if(i % FLUSH_COUNT == 0 || i == insertSqlList.size() - 1)
// {
// pstmt.executeBatch();
// connection.commit();
// }
//
// }
// isExecuteCorrect = true;
// }
// catch(SQLException e)
// {
// logger.error(e.getMessage(), e);
// }
// return isExecuteCorrect;
// }

// public void insertGroupInfoListIntoLocationMapping()
// {
// clearLocationMappingTable();
//
// String sql = "insert into LocationMapping values(?,?)";
// Connection connN3 = null;
// PreparedStatement ps = null;
// try
// {
// DataUpgradeContext context = DataUpgradeContexManager.getDataUpgradeContex();
// connN3 = DbUtil.getUepDatabaseConnection("n3common", context);
// ps = connN3.prepareStatement(sql);
// executeBatchInsert(ps);
// }
// catch(SQLException e)
// {
// e.printStackTrace();
// }
// catch(DataUpgradeException e)
// {
// e.printStackTrace();
// }
// finally
// {
// DbUtil.closeDB(connN3, ps, null);
// }
// }
//
// private void executeBatchInsert(PreparedStatement ps) throws SQLException
// {
// for(int i = 0; i < groupInfoList.size(); i++)
// {
// GroupInfo groupInfo = groupInfoList.get(i);
// ps.setString(1, groupInfo.getOid());
// ps.setString(2, groupInfo.getName());
// System.out.println("insert into LocationMapping:" + groupInfo.getName());
// ps.addBatch();
// if((i + 1) % FLUSH_COUNT == 0 || (i + 1) == groupInfoList.size())
// {
// ps.executeBatch();
// }
// }
//
// }

public void testConnCommit()
{
Connection conn = null;
PreparedStatement pstmt = null;
try
{
conn = getDBConnectionMsSqlBySuperAdmin();
conn.setAutoCommit(false);
for(int i = 0; i < 100; i++)
{
String sql = " sql " + i;
pstmt = conn.prepareStatement(sql);
pstmt.execute();
// pstmt.executeQuery();
// pstmt.executeUpdate();
}
conn.commit();
}
catch(Exception e)
{
if(conn != null)
{
try
{
conn.rollback();
}
catch(SQLException e1)
{
e.printStackTrace();
}
}
}
finally
{
if(pstmt != null)
{
try
{
pstmt.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
if(conn != null)
{
try
{
conn.setAutoCommit(true);
conn.close();
}
catch(SQLException e)
{
e.printStackTrace();
}

}
}

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值