简体   繁体   中英

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.

Can you let me know how to do it?

For easy reference I am including my SQL query

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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