繁体   English   中英

JDBC查询多个数据库

[英]JDBC query multiple databases

我想做的是查询N个数据库,并将结果通过JDBC存储在每个数据库特定的文件中。 我当时正在考虑并行执行查询,并且正在考虑通过线程池进行操作,但这是否可扩展? 有没有更好的方法(演员模型)?

谢谢。

是的,它是可扩展的。 总会有更好的方法,但是您需要确保最简单的方法适合您的需求。 如果没有,那就寻求更好的方法。

替代方法根本不需要复杂。

// initialize an executor service
ExecutorService executor = Executors.newCachedThreadPool();

// externalize the access to every database in a method declared in a class
// that implements Runnable
class Oracle implements Runnable {
  @Override
  public void run() {
    // load the driver
    // prepare the statement
    // get the connection
    // execute the statement and get the results
    // save the results to a file
  }
}

// execute every db access withing the executor
executor.execute(new Oracle());
executor.execute(new SqlServer());
executor.execute(new MySql());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM