mysql - java.sql.sqlexception column not found -


i trying find max no tr_id (primary key) in transaction table.
here table , it's layout.
enter image description here


enter image description here


here cord.

             try {                 resultset rs = db.getdata("select max(tr_id) transaction");                 resultsetmetadata meta = rs.getmetadata();                 (int index = 1; index <= meta.getcolumncount(); index++) {                     system.out.println("column " + index + " named " +    meta.getcolumnname(index));                 }                 if (rs.first()) {                     int tr_id = rs.getint("tr_id");                } 


i'm using jdbc connection. when i'm running cord i'm getting error.

        column 1 named max(tr_id)         java.sql.sqlexception: column 'tr_id' not found.     @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:910)     @ com.mysql.jdbc.resultset.findcolumn(resultset.java:955)     @ com.mysql.jdbc.resultset.getint(resultset.java:2570)     @ controler.invoicefinalising.saveinvoice(invoicefinalising.java:57)   etc.. 


thing when i'm searching out "tr_id" column name goes max(tr_id)

this because column name in sql query max(tr_id). can write as

resultset rs = db.getdata("select max(tr_id) tr_id transaction"); 

now able it.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -