Ich erhalte diese Fehlermeldung:Warum bekomme ich java.sql.SQLException: ResultSet nicht geöffnet. Operation 'next' nicht erlaubt. Java Derby Datenbank?
java.sql.SQLException: ResultSet not open. Operation 'next' not permitted. Verify that autocommit is off.
, wenn ich versuche Instanzen von einem DB zu erstellen.
Aktuelle Code:
try
{
connection.setAutoCommit(false);
stmt = connection.createStatement();
results = stmt.executeQuery("SELECT * from animalTable");
int AnimalCat = -1;
System.out.print(connection.getAutoCommit());
//getting error on line below
while(results.next())
{
int ID = results.getInt(1);
int Age = results.getInt(2);
String Name = results.getString(3);
String AType = results.getString(4);
String Breed = results.getString(5);
AnimalCat = results.getInt(6);
int Adoption = results.getInt(7);
String Gender = results.getString(8);
String Description = results.getString(9);
if(Gender == "Male"){
gen = true;
}
animal = new Animal(Age, AType, gen, Breed, Description, Name);
animalList.add(animal);
if(AnimalCat != -1){
ResultSet resultCat = stmt.executeQuery("SELECT * from CategoryTable where ID = " + AnimalCat);
//without this line below i get a cursor error
resultCat.next();
System.out.println(resultCat.getInt(1) +"\n\n " + resultCat.getString(2));
String Category = resultCat.getString(2);
if(Category == "Lost"){
Date input = resultCat.getDate(3);
LocalDate date = input.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
ResultSet personData = stmt.executeQuery("SELECT * from PersonTable where ID = " + resultCat.getInt(4));
Person person = new Person(personData.getString(2), personData.getString(3), personData.getString(4), personData.getString(5));
Category lost = new Lost(date, resultCat.getString(5), person);
animal.setAnimalCat(lost);
personList.add(person);
}
}
}
results.close();
stmt.close();
}
catch (SQLException sqlExcept)
{
sqlExcept.printStackTrace();
}
ich versucht habe, auto Ausschalten begehen, wie es in der Ausnahme sagt und auch das Hinzufügen einer finally-Block und Schließen der Erklärung. Von dem, was ich online sehe, behoben andere Probleme, aber kein Glück mit mir. irgendwie
Ich kenne die resultCat.next();
hinter dem Fehler ist, aber ich erhalte einen „Invalid Cursor-Status - keine aktuelle Zeile“ ohne es