1

Im trying to make an login code. The quick explanation is that i want to show the details of the account in a deatils page but i cant do that because an error always show that the function is not implemented in the JDBC Driver

JButton btnLogin = new JButton("Login");
    btnLogin.addActionListener(new ActionListener() {
        @SuppressWarnings("deprecation")
        public void actionPerformed(ActionEvent arg0) {
            String query = "select Username,Password from Login where Username=? and Password=?";
            try{

                PreparedStatement pst = connDB.prepareStatement(query);

                pst.setString(1,textFieldUN.getText());
                pst.setString(2, passwordField.getText());

                ResultSet rs = pst.executeQuery();
                int count= 0;
                while(rs.next()){
                    count++;
                }
                if(count == 1){
                    JOptionPane.showMessageDialog(null, "Signed In");
                    frame.dispose();
                    Details details = new Details();
                    details.setVisible(true);

                    String qwerty = " insert into LoginTemp select * from Login where Username = ? ";
                    PreparedStatement psts = connDB.prepareStatement(qwerty);
                    psts.setString(1, textFieldUN.getText());
                    psts.executeQuery(qwerty);
                }else{
                    JOptionPane.showMessageDialog(null, "Incorrect Username and Password Try again");
                }
                rs.close();
                pst.close();
            }catch(Exception e){
                JOptionPane.showMessageDialog(null, e);
            }

        }
    });

1 Answers1

2

Most likely the problem is in psts.executeQuery(qwerty); because PreparedStatement.executeQuery(String) is not implemented in the SQLite JDBC Driver.

JDBC Driver Source code: PreparedStatement.exequteQuery(String))

The PreparedStatement.exequteQuery(String) throws an SQLException("not implemented by SQLite JDBC driver");

This behavior is also described in the answer of not Implemented by SQLite JDBC driver PreparedStatement.executeQuery(String sql) is not implemented in the SQLite JDBC Driver.

You can just use psts.executeQuery(); resp. psts.executeUpdate(); without parameters here because the Query is already defined when you create the prepared statement.

Btw. ensure that you always close your PreparedStatements and ResultSets. For an explanation see Do I need to close PreparedStatement

andih
  • 5,570
  • 3
  • 26
  • 36