avhimkov
10/15/2016 - 7:11 AM

Check if resurs empty From http://javarevisited.blogspot.ru/2016/10/how-to-check-if-resultset-is-empty-in-Java-JDBC.html

import java.sql.CallableStatement; 
import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.ResultSet;  
public class DBTest {    public static void main(String args[]){      
  Connection con = null;    
try {        
  String url = "jdbc:sqlserver://localhost:42588;";       
// no need to call Class.forName(driver) from JDK 6 onward       
con = DriverManager.getConnection(url, "admin", "root");        
Statement stmt = con.createStatement();       
ResultSet rs = stmt.executeQuery("SELECT * from Employee");  
if (rs.next() == false) {        
  System.out.println("ResultSet in empty in Java"); 
} 
else {          
  do {           
    String data = rs.getString("emp_name");      
System.out.println(data);         
} 
while (rs.next());       }      } 
catch (Exception e) {       
  e.printStackTrace();     
  }    
} 
}