lundi 2 juillet 2018

Why my ELSE code pop-out error?

Someone help me, i can't figure out how to end this suffer. My idea is to create function about "When Database data same with input text will pop-out (ID Found) else (ID Not Found)

public void actionPerformed(ActionEvent e) {
        try {
            // Java style variable names.
            String Name = TextIc2.getText();

            String url = "jdbc:sqlite:DB/TestDB.db";
            Connection conn = null;
            conn = DriverManager.getConnection(url);
            //DATEIC
            String sql = "SELECT * FROM Test WHERE IDTest=?";
            ResultSet rs = null;
            PreparedStatement pstmt = null;

                pstmt  = conn.prepareStatement(sql);
                // set the value
                pstmt.setString(1,Name);
                //
                rs  = pstmt.executeQuery();
                if (rs.getString("IDTest") != null) {

                    jLblNDAic.setText(":  "  + "ID found" + ");
                    System.out.println(rs.getString("IDTest"));
                }
                else if (rs.getString("IDTest") == null) {
                    jLblNDAic.setText(":  "  + "ID not Found");
                    System.out.println(rs.getString("IDTest"));

        }} catch (SQLException e2) {
            System.out.println(e2);
            e2.printStackTrace();
        }}

java.sql.SQLException: ResultSet closed
java.sql.SQLException: ResultSet closed

Aucun commentaire:

Enregistrer un commentaire