【问题标题】:How to Retrieve Data from Two Different MySQL Database using JDBC?如何使用 JDBC 从两个不同的 MySQL 数据库中检索数据?
【发布时间】:2015-02-13 13:37:30
【问题描述】:

如何使用 jdbc 在单个查询中从两个不同的 MySQL 数据库中检索数据?

SELECT 
      a.`driver_id`,
      a.`state`, 
      a.`lat`, 
      a.`long`, 
      MAX(a.`time_stamp`) AS timestamp,
      b.vehicle_type 
 FROM `rl_driv_location` AS a, `rl_driver_info` AS b 
 WHERE a.`state` = 1 AND a.`driver_id` = b.`user_id` 
       AND b.`vehicle_type` = '"+ cartype +"'  
 GROUP BY driver_id
  • 具有rl_driv_location 表的位置数据库。
  • 具有rl_driver_info 表的核心数据库。

【问题讨论】:

    标签: java mysql jdbc


    【解决方案1】:

    只需指定要检索数据的数据库的名称。见下文。

    SELECT 
          a.`driver_id`,
          a.`state`, 
          a.`lat`, 
          a.`long`, 
          MAX(a.`time_stamp`) AS timestamp,
          b.vehicle_type 
     FROM location.`rl_driv_location` AS a, core.`rl_driver_info` AS b 
     WHERE a.`state` = 1 AND a.`driver_id` = b.`user_id` 
           AND b.`vehicle_type` = '"+ cartype +"'  
     GROUP BY driver_id
    

    【讨论】:

    猜你喜欢
    • 2012-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-04
    • 1970-01-01
    • 1970-01-01
    • 2015-01-20
    • 1970-01-01
    相关资源
    最近更新 更多