用同一个sql语句查询。
100个数据库里面的表的结构都是相同的。
我现在要做的就是::需要同时链接100个数据库进行查询。查出一条符合 条件的就显示一条。。
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://192.168.20.236:3306/express001","root" ,"123456");
ps=conn.prepareStatement("select * from sf where f29=? or f30=? or f40=? or f41=?");
这是连接1个数据库的时候。。。
有什么好办法可以解决嘛
多线程能解决吗??我没有接触过多线程,,如果可以,还请麻烦给点提示 谢谢。。。
No test, you try it
I think multi-threading can solve it...otherwise it will be executed synchronously.
Is there any good way to do this? Connect them one by one. The number of threads should be the number of CPU cores. Too many are a waste of resources. Use a thread pool.
Since you want to operate 100 libraries, you naturally need 100 different connections. This is a hard condition.
Give the poster an open source project from Dangdang.com.
sharding-jdbc
If it is Oracle, you can use dblink. If you are not the original poster, you can use mysql. You may only be able to connect to 100 databases to query separately, and finally summarize them. If you use multiple threads to query these 100 databases separately, you need to pay attention to thread safety issues during aggregation