java - JDBC查询多个数据库

标签 java jdbc parallel-processing

我想要做的是通过 JDBC 查询 N 个数据库并将结果存储在每个数据库特定的文件中。我正在考虑并行执行查询,并通过线程池进行思考,但是这样可以扩展吗?有更好的方法( Actor 模型)吗?

谢谢。

最佳答案

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

替代方法根本不必复杂。

// 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());

关于java - JDBC查询多个数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9260848/

相关文章:

java - 为什么我在 R 和 Java 中得到简单线性回归的截距值不同?

java - 使用 libphonenumber 确定国家运营商代码

bash - 使用 xargs 并行运行程序

windows - 如何在一个窗口内运行多个进程的 Delphi 中创建类似 Chrome 的应用程序?

math - 用cuda计算二进制NxN矩阵的行列式

java - 修改服务层Spring data Page<>类投影响应

java - 在 Java 中使用 Rest API 上传文件

java - 使用 AutoGenerateKeys 和 Oracle 时出现 ArrayIndexOutOfBoundsException

Java, JDBC : Does closing a PreparedStatement also free up its memory footprint in the database connection?

java - 从 jOOQ 事务访问 JDBC 连接