I am coding a simple CRUD application in java and I have a method for selecting Produkts that comes with bills.
Here is my code:
public Rechnung selectProdukte(int target){ int tempProdukt; int tempAnzahl; try { PreparedStatement ps1=hsqlmanager.getConnection().prepareStatement("SELECT produkt, anzahl from gekauftes_produkt " + "WHERE rechnung= " + target + ";"); //ps1.setInt(1, target); //Query 1wird executiert PreparedStatement ps2 = hsqlmanager.getConnection().prepareStatement("SELECT * FROM rechnung WHERE id= " + target + ";"); //ps2.setInt(1, target); ResultSet rs1 = ps1.executeQuery(); ResultSet rs2 = ps2.executeQuery(); Rechnung erg=new Rechnung(); erg.setId(rs2.getInt(1)); erg.setDatum(rs2.getDate(2)); erg.setSumme(rs2.getDouble(3)); while(rs1.next()){ tempProdukt=rs1.getInt(1); tempAnzahl=rs1.getInt(2); erg.addGekauftTupel(tempProdukt, tempAnzahl); } ps1.close(); ps2.close(); return erg; } catch(Exception e) { log.error("Fehler in DAO Rechnung - selectProdukte: " + e); } return null; }
When I click the button to execute the code, I get:
java.sql.SQLException: invalid cursor state: identifier cursor is not positioned in a line in UPDATE, DELETE, SET or GET :; ResultSet is positioned before the first line
I checked db and all tables and entities exist. So my question is:
What does it mean?
I appreciate your answer !!!
PS: I am using hsql db!
source share