i try to select from my table, only select the last row. I've tried this :
rset = s.executeQuery("select noorder from orders");
rset.last();
String noorder = rset.getString("noorder");`
rset is resultset, and s is statement. But it throw an exception : ResultSet may only be accessed in a forward direction`
I've tried this to :
if (rset != null) {
while(rset.next()){
rset.last();
}
}
Am I doing wrong? Any idea? Thanks
Edit :
This is the answer, as suggested by @Bhavik-Ambani (thanks for him). And this is my code :
Statement s2 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rset = s2.executeQuery("select noorder from orders");
rset.afterLast();
GETLASTINSERTED:
while(rset.previous()){
noorder = rset.getString("noorder");
break GETLASTINSERTED;//to read only the last row
}
Hope it will be help another. Java rocks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…