String sqlpre = "update SPD_DOMAIN set IS_CHINESE_SITE = ? ,ALEXA_RANKING = ?where DOMAIN= ?";
Connection conn=null;
PreparedStatement ptmt = null;

try {
conn.setAutoCommit(false);
conn = PoolManager.getConnection();
ptmt = conn.prepareStatement(sqlpre);
for(int i=0;i<ub.length;i++){
ptmt.setLong(1,ub[i].getIsChineseSite());
ptmt.setLong(2, ub[i].getAlexaRanking());
ptmt.setString(3, ub[i].getDomain());
ptmt.executeUpdate();
}
conn.commit();上面是java代码 ,已经用了绑定变量了,但还想用批处理,能一起用吗

解决方案 »

  1.   

    这个问题好像到java版问更合适。
      

  2.   

    可以. 设计一个PROCEDURE, 然后使用JAVA调用.
      

  3.   

    建议你用ub这个数组迭代出来所有的update语句,最后统一用begin update.....; update....;.... end;提交执行,这样效率会高,只与数据库通信一次
      

  4.   

    用Spring的批量比较好:public void batchInsertRows(String sql,final List<Object[]> dataSet) throws Exception{
    BatchPreparedStatementSetter setter=new BatchPreparedStatementSetter(){
    public int getBatchSize(){
    return dataSet.size();
    }
    public void setValues(PreparedStatement ps,int i){
    Object[] obj = dataSet.get(i);
    int nextId = getNextId();
    try{
    ps.setLong(1,nextId);
    ps.setLong(2,Integer.parseInt(obj[0].toString()));
    ps.setLong(3,Integer.parseInt(obj[1].toString()));
    ps.setString(4,(String)obj[2]);}
    catch(Exception e){
    e.printStackTrace();
    }
    }
    };
    jdbcTemplate.batchUpdate(sql,setter);
    }