⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maintestforbatchsqlupdate.java

📁 随书光盘:精通Sping 2.0 的随书源代码
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -