I am trying to find max no from tr_id (primary key) in transaction table.
Here is the table and it's layout.


Here is my cord.
try {
ResultSet rs = db.getData("SELECT MAX(tr_id) FROM transaction");
ResultSetMetaData meta = rs.getMetaData();
for (int index = 1; index <= meta.getColumnCount(); index++) {
System.out.println("Column " + index + " is named " + meta.getColumnName(index));
}
if (rs.first()) {
int tr_id = rs.getInt("tr_id");
}
I'm using JDBC connection. When I'm running this cord I'm getting this error.
Column 1 is named MAX(tr_id)
java.sql.SQLException: Column 'tr_id' not found.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:955)
at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:2570)
at Controler.InvoiceFinalising.saveInvoice(InvoiceFinalising.java:57)
etc..
The thing is when I'm searching out as "tr_id" column name goes to Max(tr_id)