SQLITE / JAVA:数据库文件已锁定(数据库已锁定)

时间:2019-05-07 13:00:04

标签: java sqlite

输入第二个函数时出现此错误。我知道当有另一个未关闭的连接时,我不应该打开连接,但是我确定我已经在第一个函数choisirBien()的结尾处将其关闭。它在其余的代码中都能正常工作,但在这里却不行,我也不明白为什么。 谢谢你的帮助。

public static ArrayList choisirBien() throws ClassNotFoundException, SQLException{
    Connection conn = null;
    Statement stmt = null;
    Statement stmt2 = null;
    Class.forName("org.sqlite.JDBC");
    conn = DriverManager.getConnection("jdbc:sqlite:bdd.db");
    stmt = conn.createStatement();
    stmt2 = conn.createStatement();
    ArrayList<String> liste_biens=new ArrayList<>();
    ArrayList liste_resultat=new ArrayList<>();

    ResultSet res = stmt.executeQuery("SELECT * FROM biens_immobiliers WHERE en_ligne =1");
    while (res.next()){
           String bien = res.getString("nom");
           liste_biens.add(bien);
            }
            String[] liste_biens_simple = new String[ liste_biens.size() ];
            liste_biens.toArray( liste_biens_simple );
            String choix_bien = Dialogue.choisirBien(liste_biens_simple);
            liste_resultat.add(choix_bien);
            ResultSet res2 = stmt2.executeQuery("SELECT * FROM biens_immobiliers WHERE nom LIKE '"+choix_bien+"'");
            while (res2.next()){
                int id_bien = res2.getInt("id_bien");
                liste_resultat.add(id_bien);

            }

    //I'm closing right here
    stmt.close();
    stmt2.close();
    res.close();
    res2.close();
    conn.close();

    return liste_resultat; 

 }




public static int donnerInfoRdv() throws ClassNotFoundException, SQLException{
    String nom = Dialogue.nom();
    String prenom = Dialogue.prenom();
    Connection conn = null;
    Statement stmt = null;
    Class.forName("org.sqlite.JDBC");
    conn = DriverManager.getConnection("jdbc:sqlite:bdd.db");
    stmt = conn.createStatement();
    if (BDD.est_dans_BDD("particulier", "nom", nom)==true && BDD.est_dans_BDD("particulier", "prenom", prenom)==true){
        ResultSet res = stmt.executeQuery("SELECT * FROM particulier WHERE nom LIKE "+nom+" AND prenom LIKE "+prenom);
        while (res.next()){
               String email = res.getString("email");
               String telephone = res.getString("telephone");
               int id_particulier = res.getInt("id_individu");
                int confirmation = Dialogue.confirmation("Êtes-vous bien "+prenom+" "+nom+" ?\n"+email+"\n"+telephone);
                if (confirmation==1){
                    return id_particulier;
                }

        }

    }
    else{
    xxxx
    return id_particulier;
    }
    return 0;
}



public static void main(String[] args) throws ClassNotFoundException, SQLException, IOException, ParseException {
    ArrayList liste_resultat=choisirBien();
    int id_particulier = donnerInfoRdv();


}

0 个答案:

没有答案