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

📄 maintestforupdatablesqlquery.java

📁 随书光盘:精通Sping 2.0 的随书源代码
💻 JAVA
字号:
package test;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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.core.SqlParameter;
import org.springframework.jdbc.object.UpdatableSqlQuery;

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

	private static final Log log = LogFactory.getLog(MainTestForUpdatableSqlQuery.class);
	
	public static void main(String[] args) {		
		ListableBeanFactory cbf = new ClassPathXmlApplicationContext("ac1.xml");		
		GenericBeanFactoryAccessor gbfa = new GenericBeanFactoryAccessor(cbf);
		
		DataSource ds = gbfa.getBean("dataSource");
		
		//为更新操作提供可选的上下文信息
		Map<Integer, String> map = new HashMap<Integer, String>();
		map.put(4, "Xxx");
		
		OwnersUpdateQuery ouq = new OwnersUpdateQuery(ds);
		List list = ouq.execute(7934, map);
		
		log.info(list);
	}

}

class OwnersUpdateQuery extends UpdatableSqlQuery {

	public OwnersUpdateQuery(DataSource ds) {
		super(ds, "select ename from emp where empno = ?");
		declareParameter(new SqlParameter(Types.INTEGER));
		compile();
	}

	protected Object updateRow(ResultSet rs, int rownum, Map context) 
		throws SQLException {
		rs.updateString(1, "" + rs.getString("ename") + " " + context.get(4));
		return rs.getString("ename");
	}
	
}

⌨️ 快捷键说明

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