Operation not allowed for a result set of type ResultSet.TYPE_FORWARD_ONLY.

public reading() {
ResultSet rs;
try {
Statement st;
String sql = "SELECT * from utility";
st = con.createStatement();
rs = st.executeQuery(sql);

rs.last();
System.out.println(rs.getInt("reading"));

} catch (Exception e) {
System.err.println(e);
}
}
public reading() {
ResultSet rs;
try {
Statement st;
String sql = "SELECT * from utility";
st = con.createStatement();
rs = st.executeQuery(sql);

rs.last();
System.out.println(rs.getInt("reading"));

} catch (Exception e) {
System.err.println(e);
}
}
rs.last() is the cause of the problem. I have no problem when I use
rs.next()
rs.next()
. But the thing is, I only need to retrieve the last row of the reading column instead of retrieving everything. I also tried putting
rs.last()
rs.last()
in
if-else
if-else
3 Replies
JavaBot
JavaBot9mo ago
This post has been reserved for your question.
Hey @GeneralCore! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
GeneralCore
GeneralCoreOP9mo ago
Oh, I actually fixed it now with the help of gemini. I had to change this from
st = con.createStatement();
st = con.createStatement();
to
st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
I have already done this before, and I did not add argument in con.createStatement before, and it did not show any errors. Why is that? T - T
JavaBot
JavaBot9mo ago
Post Closed
This post has been closed by <@307017632287162369>.

Did you find this page helpful?