sqlite未在JDBC Driver中实现

时间:2017-06-12 09:55:53

标签: java sqlite jdbc

我正在尝试制作登录代码。快速解释是我想在deatils页面中显示帐户的详细信息,但我不能这样做,因为错误总是显示该函数未在JDBC驱动程序中实现

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 个答案:

答案 0 :(得分:2)

问题很可能出在psts.executeQuery(qwerty);,因为SQLite JDBC驱动程序中没有实现PreparedStatement.executeQuery(String)

JDBC驱动程序源代码:PreparedStatement.exequteQuery(String)

PreparedStatement.exequteQuery(String)会引发SQLException("not implemented by SQLite JDBC driver");

not Implemented by SQLite JDBC driver PreparedStatement.executeQuery(String sql)的答案中也描述了这种行为在SQLite JDBC驱动程序中没有实现。

您可以使用psts.executeQuery(); resp。这里没有参数的psts.executeUpdate();因为在创建预准备语句时已经定义了Query。

顺便说一下。确保您始终关闭PreparedStatementResultSet。 有关解释,请参阅Do I need to close PreparedStatement