java - Illegal operation on empty result set - how to check if it's empty? -


this question has answer here:

i've got problem java plugin - when there's no results found says result set empty. tell me how detect if result set empty?

string url = "jdbc:mysql://" + host + ":" + port + "/" + database + "";  connection conn = drivermanager.getconnection(url, username, password); statement stmt = conn.createstatement();  resultset rs; string p = pp.getname(); rs = stmt.executequery("select * " + table + " username='"         + p + "' , recieved=0 order id desc"); rs = stmt.getresultset(); 

the standard approach attempt next row using next() method, , check if returned false (meaning there no next row, it's empty). this:

resultset rs; // run query on database if (!rs.next()) {     // no row(s) found database } else {     // row(s) found database ok } 

it can convenient code do...while loop:

if (!rs.next()) {     // handle no rows found } else {     // process rows     {         // process row     } while (rs.next()); } 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -