Can someone please tell me how to get rid of the Exhausted Resultset exception. I have tried looking at other questions posted on this site but nothing seems to be helping. I am getting the error even after using the .next() method. Btw, the sql code does return rows, and it is not an empty set. This is my code:
package jdbcManabu;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
public class TwoTables
{
public static void main(String[] args)
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection tsunagu = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "hr", "hr");
Statement gyo = tsunagu.createStatement();
String sql1 =
"SELECT e1.salary, e2.salary FROM employees e1 INNER JOIN employees e2 ON e1.employee_id = e2.employee_id WHERE e1.salary > 20000";
ResultSet set1 = gyo.executeQuery(sql1);
ResultSetMetaData meta1 = set1.getMetaData();
for(int i=1; i <= meta1.getColumnCount(); i++)
System.out.print(meta1.getColumnName(i) + "=" + meta1.getColumnTypeName(i));
int clmns = meta1.getColumnCount();
while(set1.next());
{
for(int i = 1; i <= clmns; i++)
{
System.out.print( set1.getInt(i) + " ");
}
System.out.println();
}
tsunagu.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}