簡體   English   中英

如何使用多個表在JDBC連接中獲取數據?

[英]How to use multiple tables to get the data in JDBC connectivity?

您好,我正在用SQL編寫查詢,該查詢從多個表中獲取數據,並從結果集中檢索數據,我們需要從對應的表中執行rs.getString(1) ,但對我而言,數據來自多個表。

你能讓我知道怎么做嗎?

為了便於參考,我包括了我的SQL查詢

select EID,sport,emich_email, lastname,firstname,numtodsinterval(sum(
  extract(day from dd) * (24 * 60 * 60)
    + extract(hour from dd) * (60 * 60)
    + extract(minute from dd) * 60
    + extract(second from dd)
  ), 'SECOND') as total_hours
from (
  select scans.emich_email,EID,lastname,firstname,Sport, sign_out - sign_in as dd from scans INNER JOIN student_details ON scans.emich_email=student_details.emich_email INNER JOIN Athlete ON student_details.EID=Athlete.EID)
group by emich_email,EID,lastname,firstname,sport;

您應該能夠使用別名來恢復列,例如

select name as the_name, surname as the_surname from employees where...

然后通過其別名從ResultSet恢復每一列

String myName = rs.getString("the_name");
String mySurname = rs.getString("the_surname");
...

如果您仔細選擇別名,則可以嘗試以下操作:

select table1.xxx as table1_xxx, table1.yyy as table1_yyy, ...., table3.zzz as table3_zzz from table1 join table2 on ...

我不知道這是否是您所需要的,但是也許這對您或至少更具可讀性的Java代碼很有用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM