This is the code for jdbc which is written in eclipse. I am just trying to store the result of the query to ResultSet rs and adding it to String name. But on execution the below code i am facing Exhausted Resultset error.
import java.sql.*;
public class DemoClass{
public static void main(String args[]) throws Exception{
String query = "SELECT name FROM Emp WHERE rollno=1";
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "Subhro", "Kabiraj");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query);
rs.next();
String name = rs.getString("name");
System.out.println(name);
st.close();
con.close();
}
}
ERROR:
Exception in thread "main" java.sql.SQLException: Exhausted Resultset
at ojdbc6@11.2.0.4/oracle.jdbc.driver.OracleResultSetImpl.getString(OracleResultSetImpl.java:1270)
at ojdbc6@11.2.0.4/oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:498)
at DemoClass.main(DemoClass.java:14)
Note: my table is not empty.
TABLE created in terninal:
SQL> INSERT INTO Emp(rollno, name) values(1, 'abc');
1 row created.
SQL> INSERT INTO Emp(rollno, name) values(2, 'def');
1 row created.
SQL> INSERT INTO Emp(rollno, name) values(3, 'ghi');
1 row created.
SQL> select * from Emp
2 ;
ROLLNO
----------
NAME
--------------------------------------------------------------------------------
1
abc
2
def
3
ghi
SQL> SELECT name FROM Emp WHERE rollno=1;
NAME
--------------------------------------------------------------------------------
abc
Any suggestions how to get rid of this error.