ZeroBz的博客

生来何须久睡,死后必定长眠

线程池 抓取数据库信息

@Async(ThreadPoolConfig.EXECUTOR_NAME)
public void transferData() throws SQLException, CloneNotSupportedException {
		
	String srcUrl = DBURL.getURL(DBURL.DBTYPE_SQLSERVER, "10.10.1.47", "1433", "srcdbname");
	String srcUser = "sa";
	String srcPasswd = "123456";
		
	String targetUrl = DBURL.getURL(DBURL.DBTYPE_MYSQL, "10.10.1.47", "3306", "targetdbname");
	String targetUser = "root";
	String targetPasswd = "123456";
		
	DruidDataSource srcDataSource = createDataSource(DBURL.DBTYPE_SQLSERVER, srcUrl, srcUser, srcPasswd);
	SqlRunner srcSqlRunner = SqlRunner.create(srcDataSource);
	DruidDataSource targetDataSource = createDataSource(DBURL.DBTYPE_MYSQL, targetUrl, targetUser, targetPasswd);
	SqlRunner targetSqlRunner = SqlRunner.create(targetDataSource);
		
	List<Entity> dictionaryWordList = srcSqlRunner.findAll("srctbname");
	List<Entity> targetDictionaryWordList = new ArrayList<>();
	for (Entity entity : dictionaryWordList) {
			
	        Entity targetEntity = Entity.create("targettbname")
			            .set("targetfield1", entity.getObj("srcfield1"))
				    .set("targetfield2", entity.getObj("srcfield2"));
			
	        targetDictionaryWordList.add(targetEntity);
	}
		
	logger.info("写入开始时间:" + new Date().toString());
	targetSqlRunner.insert(targetDictionaryWordList);
	logger.info("写入结束时间:" + new Date().toString());
		
	srcDataSource.clone();
	targetDataSource.close();
}

http://hutool.mydoc.io/

个人笔记,仅供参考
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ZeroBz/article/details/79951027
个人分类: 代码常用知识
上一篇QueryRunner(DbUtils) 结果集实例
下一篇阿里巴巴druid可视化
想对作者说点什么? 我来说一句

抓取国家统计局2016地址数据库

2017年11月03日 16.51MB 下载

没有更多推荐了,返回首页

关闭
关闭