在oracle配置文件中配置相关的bean
<bean id="dataSourceOracle" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc_oracle_driver}" />
<property name="url" value="${jdbc_url_oracle}" />
<property name="username" value="${jdbc_username_oracle}" />
<property name="password" value="${jdbc_password_oracle}" />
<property name="maxTotal" value="20"></property>
<property name="maxWaitMillis" value="10000"></property>
<property name="maxIdle" value="15"></property>
<property name="minIdle" value="10"></property>
<property name="initialSize" value="15"></property>
<property name="testOnBorrow" value="true"></property>
<property name="testWhileIdle" value="true"></property>
<property name="validationQuery" value="select 1 from dual"></property>
</bean>
<bean id="jdbcTemplateOracle" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSourceOracle" />
</bean>
动态根据结果集总数量定长分页查询
例如一个sql直接查出几十万条数据,可能直接把堆撑爆了,所以设计每次查几万条
//创建bean实例
JdbcTemplate jdbcTemplateOracle = SpringContextUtil.getBean("jdbcTemplateOracle");
//查询需要同步项目的总数量,Integer.class---返回结果的数据类型
int count = jdbcTemplateOracle.queryForObject("select count(0) from \"table\" t where t.aedat <", Integer.class);
//分页sql,分页参数问号占位
String sql = "SELECT * FROM(select rownum AS rnum, t.* from \"table\" t where rownum <= ? )WHERE rnum > ?";
//默认第一次分页的最后索引为10000
int endIndex = 10000;
//存放参数集合
List<Object> params = new ArrayList<>();
//循环查询插入,默认第一次分页起始索引为0,每次循环结束后,起始结束索引都加10000
for(int startIndex = 0; startIndex < count ; startIndex += 10000){
params.clear();
params.add(endIndex);
params.add(startIndex);
//查询
List rows = jdbcTemplateOracle.queryForList(sql,params.toArray());
Iterator iterator = rows.iterator();
//遍历结果集
Map rs = (Map) iterator.next();
String a = rs.get("a").toString();
//..........
endIndex += 10000;
}