Get max value sql in Java -


*i don't value of max in function other. value return "0". trying not success :( image

public int pricemax(int manhom){         connection conn = this.connect();         int max = 0;         if(conn != null){             try {                 java.sql.statement statement = conn.createstatement();                 string sql = "select avg(giasp) tbsanpham manhom = '"+manhom+"'";                 resultset rs = statement.executequery(sql);                 max = rs.getint(sql);             } catch (sqlexception ex) {                 logger.getlogger(csdl.class.getname()).log(level.severe, null, ex);             }         }         return max;     } 

help!!!

int manhom = cbbnhomsanpham.getselectedindex();         csdl csdl = new csdl();         int max = csdl.pricemax(manhom);         joptionpane.showmessagedialog(null, "nhóm sản phẩm: '"+cbbnhomsanpham.getname()+"' \nprice max: '"+max+"' "); 

you're not using should be.

first of all, use Àvg want max change max(giasp). second, must use rs.next() have cursor go first row , information it.

java.sql.statement statement = conn.createstatement(); string sql = "select max(giasp) tbsanpham manhom = '"+manhom+"'"; resultset rs = statement.executequery(sql); if (rs.next()) {     max = rs.getint(1); } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -