Problem using MAX word in MYSQL

Hi,

I have tried to do a mysql query using the follwing sentence , but it doesn’t works:

def query= "";
query="select max(test_id)  from test"

What i’m trying to do is to retrieve the highest value and then increase it . Here is the Grovy script:

resultset.beforeFirst();
Long id = null;
if (resultset.next()) {
id = resultset.getLong('test_id');
++id;
}
return id;

The mistake are in the mysql sentence , because i have tried this other mysql sentence without the MAX word and it works good.

query="select test_id  from test"

Regards.

Hi,

change your query to select max(test_id) as max_test_id from test and use this alias in resultset.getLong('max_test_id')