maintestforbatchsqlupdate.java

来自「随书光盘:精通Sping 2.0 的随书源代码」· Java 代码 · 共 40 行

JAVA
40
字号
package test;

import java.sql.Types;

import javax.sql.DataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.generic.GenericBeanFactoryAccessor;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.object.BatchSqlUpdate;

/**
 * 
 * @author worldheart
 *
 */
public class MainTestForBatchSqlUpdate {

	private static final Log log = LogFactory.getLog(MainTestForBatchSqlUpdate.class);
	
	public static void main(String[] args) {		
		ListableBeanFactory cbf = new ClassPathXmlApplicationContext("ac2.xml");		
		GenericBeanFactoryAccessor gbfa = new GenericBeanFactoryAccessor(cbf);
		
		DataSource ds = gbfa.getBean("dataSource");
		
		final int[] no = new int[]{7369,7499,7521,7566,7654,7698};
		
		BatchSqlUpdate bsu = new BatchSqlUpdate(ds, "update emp set sal = ? where empno = ?");
		bsu.setBatchSize(4);
		bsu.setTypes(new int[]{Types.FLOAT, Types.INTEGER});
		for(int i = 0; i < no.length; ++i){
			log.info(bsu.update(new Object[]{no[i],no[i]})) ;
		}
		bsu.flush();
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?