我已经得到了错误耗尽的结果集,但我并不知道我在做什么,我基本上是试图在我的uni项目中从一个数据库存储3行到一个名为“Logement”的类的3个元素的数组中,这个类稍后将用于填充javafxui中的多个复选框
package accesBD;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import metier.ConvIntToBool;
import metier.Logement;
public class LogementDAO {
TypeLogementDAO bd = new TypeLogementDAO();
public Logement[] findAll() throws SQLException {
Logement logements[] = null;
Connection cnx= SConnection.getInstance();
Logement logement = null;
try {
PreparedStatement st= cnx.prepareStatement("select* from logement");
ResultSet res= st.executeQuery();
int i =0;
while (res.next()) {
logement= new Logement(bd.find(res.getInt(1)), ConvIntToBool.boolToInt(res.getInt(2)) ,ConvIntToBool.boolToInt(res.getInt(3)),ConvIntToBool.boolToInt(res.getInt(4)),ConvIntToBool.boolToInt(res.getInt(5)),ConvIntToBool.boolToInt(res.getInt(6)));
//System.out.println(res.getRow());
logements[i]=logement;
i++;
}
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
return logements;//la collection retournée peut être vide
}
}
public TypeLogement find(int id){
Connection cnx =SConnection.getInstance();
TypeLogement c=null;
try {PreparedStatement stp1=cnx.prepareStatement("select * from typelogement where id=?");
stp1.setInt(1, id);
ResultSet n= stp1.executeQuery();
while(n.next()){
c= new TypeLogement(n.getInt(1),n.getString(2),n.getDouble(3));
}
cnx.close();
} catch (SQLException e) {
e.printStackTrace();
}
return c;
}