简体   繁体   English

如何使用多个表在JDBC连接中获取数据?

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

Hello I am writing a query in SQL that gets data from multiple tables and in retrieving data from resultset, we need to do rs.getString(1) from the corresponding table, but for me the data comes from multiple tables. 您好,我正在用SQL编写查询,该查询从多个表中获取数据,并从结果集中检索数据,我们需要从对应的表中执行rs.getString(1) ,但对我而言,数据来自多个表。

Can you let me know how to do it? 你能让我知道怎么做吗?

For easy reference I am including my SQL query 为了便于参考,我包括了我的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;

You should be able to recover the columns with an alias, like in 您应该能够使用别名来恢复列,例如

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

and then recover each column from your ResultSet by its alias 然后通过其别名从ResultSet恢复每一列

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

If you choose carefully your alias, you could try this: 如果您仔细选择别名,则可以尝试以下操作:

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

I don't know if this is what you need, but maybe this can be useful to you or at least a bit more readable java code 我不知道这是否是您所需要的,但是也许这对您或至少更具可读性的Java代码很有用

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

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