1w多条记录 纯粹的update 居然用了1分钟!! delete用了30秒! 有何优化的

private static final String UPDATE_0="update tb_sys_client_business_ext set m_status=?,m_regdate=?,m_unregdate=null where m_usid=? and m_type=? ";

private static final String UPDATE_1="update tb_sys_client_business_ext set m_status=?,m_unregdate=? where m_usid=? and m_type=? ";

/**
 * 修改 将allList里的数据统一更新为0 或者是1
 * @param status 状态
 * @param list  已存在的商户号
 * @param allList  需要设置的商户
 * @throws Exception
 */
public void setAllUpdate(String status,List<Business_extForm> allList) throws Exception{
	Connection conn=DBManager.getConnection();
	PreparedStatement pst=null;
	String sql="";
	Timestamp now=DateLib.now();
	try {
		Business_extForm bf = null;int i;
		conn.setAutoCommit(false);
		System.out.println("start:"+System.currentTimeMillis());
		while(allList.size()!=0){
		     i=0;
		     sql=sql(status);
		     pst=conn.prepareStatement(sql);
		     try {
		    	 while(allList.size()!=0)
			     {
		    	    bf=allList.remove(0);
			    	pst.setString(1,status);
					pst.setTimestamp(2,now);
					pst.setString(3,bf.getM_usid());
					pst.setString(4,bf.getM_type());
					pst.addBatch();
					pst.clearParameters();
				    i++;
                   if (i == 100)
                   break;
                }
				 if (i > 0)
					 pst.executeBatch();
				 	 conn.commit();
			} catch (Exception e) {
				 conn.rollback();
				 throw e;
			}
			 pst.close();
		}
		System.out.println("  end:"+System.currentTimeMillis());
	} catch (Exception e) {
		throw e;
	}finally{
		conn.close();
	}
}

ps: 1、表是这样设计的 一个id对应多个业务类型~~ allList里面相当于(id会有重复) 一个商户号里有多个业务类型 2、sqlserver 优化, java代码 优化, 分割多个try catch 优化。

如题

转载于:https://my.oschina.net/didiaomo2014/blog/119043

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值