测试环境:
springframework 1.0
数据库:Informix 9.21.FC1
表结构:
Column name Type Nulls
f1 varchar(10,0) yes
f2 varchar(10,0) yes
f3 varchar(10,0) yes
f4 varchar(10,0) yes
f5 varchar(10,0) yes
f6 varchar(10,0) yes
f7 varchar(10,0) yes
f8 varchar(10,0) yes
f9 varchar(10,0) yes
f10 varchar(10,0) yes
在f1上建立索引
测试情况:
case 1:SQL单个提交,不prepare,使用BaseDAOJdbc的executeSql方法
case 2:SQL单个提交,prepare,方法如下:
public void saveDataSinglePrepare(final List data) {
getJdbcTemplate().execute(insertData,
new PreparedStatementCallback() {
public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
Iterator iter = data.iterator();
while (iter.hasNext()){
Object[] objs = (Object[]) iter.next();
for(int i=0; i
ps.setObject(i+1, objs[i]);
}
ps.execute();
}
return null;
}
}
);
}
case 3:SQL批量提交,使用BaseDAOJdbc的executeBatch方法
/**
* Jdbc sql的批量操作
* @param sql sql语句
* @param values 包含参数的List,List的每个元素是一个Object[],Object[]是一个单独的sql操作所需的参数
*/
public void executeBatch(final String sql, final List values){
if (values.size() == 0) return ;
getJdbcTemplate().batchUpdate(sql,
new BatchPreparedStatementSetter() {
public void setValues(PreparedStatement ps, int i) throws SQLException {
Object[] args = (Object[]) values.get(i);
for(int j=0; j
///log.debug(String.valueOf(j+1)+":"+args[j].toString());
ps.setObject(j+1, args[j]);
}
}
public int getBatchSize() {
return values.size();
}
}
);
}
case 4:SQL批量提交,使用BaseDAOJdbc的executeBatch2方法
private static final int batch_size = 100;
public void executeBatch2(final String sql, final List values){
getJdbcTemplate().execute(sql,
new PreparedStatementCallback() {
public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
Iterator iter = values.iterator();
int sqlCount = 0;
while (iter.hasNext()){
if (sqlCount >= batch_size){
ps.executeBatch();
sqlCount = 0;
//log.info("executeBatch:" + sql);
}
Object[] args = (Object[]) iter.next();
for(int i=0; i
ps.setObject(i+1, args[i]);
}
ps.addBatch();
sqlCount ++;
log.debug("sqlCount:" + String.valueOf(sqlCount));
}
if (sqlCount > 0){
ps.executeBatch();
sqlCount = 0;
//log.info("executeBatch:" + sql);
}
return null;
}
}
);
}
posted on 2009-06-19 13:44
扭曲的铅笔 阅读(935)
评论(0) 编辑 收藏 所属分类:
J2EE