JDBC中进行批处理操作的例子

直接上一个代码例子就好了:

	//批量添加数据至数据库中
	public int batchAddQueryParamInfo(final List<QueryParamInfo> list) throws DAOException {
		
		int[] result = this.getJdbcTemplate().batchUpdate(  
                "insert into " + SchemaUtil.getCMSSchema() +"s_queryinfo_save(QUERYINFO_ID,PARAM_CODE,PARAM_VALUE,IMSI,APP_ID,SEQ_ID,CREATE_TIME) values (?, ?, ?, ?, ?,?,sysdate)",  
                new BatchPreparedStatementSetter() {  
               //为prepared statement设置参数。这个方法将在整个过程中被调用的次数  
               public void setValues(PreparedStatement ps, int i) throws SQLException {  
	            	    QueryParamInfo qpinfo = list.get(i);
	            	    ps.setLong(1, qpinfo.getQueryinfoId());  
	                    ps.setString(2, qpinfo.getParamCode());  
	                    ps.setString(3, qpinfo.getParamValue());  
	                    ps.setString(4, qpinfo.getImsi());
	                    ps.setLong(5, qpinfo.getAppId());
	                    ps.setLong(6, qpinfo.getSeqId());
                  }  
                  //返回更新的结果集条数  
                 public int getBatchSize() {  
                       return list.size();   
                  }  
                }); 
		
		return result.length;
	}


你可能感兴趣的:(数据库,jdbc,list,insert)