-2

If there are some identical row names in Table1 and Table2 table then how to read them in java? Currently, for reading the column values I use table1.coulmn_name. But it will only return the Table1 column value.

Table1 executeQuery(String billId)
    {
        ResultSetHandler<Table1> resultHandler = new BeanHandler<Table1>(Table1.class)       
        table1 table1 = run.query("SELECT * FROM Table1 JOIN Table2 ON Table1.payment_id =Table2.payment_id WHERE Table1.bill_id="+billId, resultHandler)

        return table1
    }
Ash
  • 11
  • 3
  • 1
    Show us some sample table data and the expected result - all as formatted text, not images. And read [mcve]. – jarlh Jan 13 '20 at 15:00
  • Ever tried table2.column_name? – Nicktar Jan 13 '20 at 15:01
  • Unrelated to your problem, but: please do not concatenate parameters to your SQL string like that. Learn how to properly use a `PreparedStatement` –  Jan 13 '20 at 15:01

2 Answers2

1

You mean identical column names. Rows don't have names in SQL.

A best practice is to list the columns you want instead of using select *:

select t1.col1, t2.col2, . . . 

If two columns have the same name, use as to assign a new name:

select t1.col1, t2.col1 as t2_col1, . . .

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

You can use the index of the column. For example:

ResultSet rs = ...
while (rs.next) {
  int ida = rs.getInt(1); // id from Table1 in column #1
  int idb = rs.getInt(2); // id from Table2 in column #2
}
Joe DiNottra
  • 836
  • 8
  • 26