线程池 抓取数据库信息

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ZeroBz/article/details/79951027
@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/

个人笔记,仅供参考
阅读更多
想对作者说点什么? 我来说一句

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