【问题标题】:sqlite not implemented in JDBC Driver [duplicate]sqlite 未在 JDBC 驱动程序中实现 [重复]
【发布时间】:2017-11-13 18:11:46
【问题描述】:

我正在尝试制作登录代码。快速解释是我想在 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);
            }

        }
    });

【问题讨论】:

  • 什么功能?如果您有连接,则存在 SQLLite 驱动程序。不清楚你在问什么。
  • connDB 是在哪里定义的?
  • 显示错误!

标签: java sqlite jdbc


【解决方案1】:

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

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

PreparedStatement.exequteQuery(String) 抛出 SQLException("not implemented by SQLite JDBC driver");

not Implemented by SQLite JDBC driverPreparedStatement.executeQuery(String sql) is not implemented in the SQLite JDBC Driver 的答案中也描述了这种行为。

你可以只使用psts.executeQuery(); resp。 psts.executeUpdate(); 此处不带参数,因为在创建准备好的语句时已经定义了查询。

顺便说一句。确保您始终关闭您的 PreparedStatements 和 ResultSets。 解释见Do I need to close PreparedStatement

【讨论】:

    猜你喜欢
    • 2016-01-01
    • 2016-08-18
    • 2019-09-17
    • 2014-07-30
    • 2012-04-13
    • 2020-03-08
    • 1970-01-01
    • 1970-01-01
    • 2015-11-06
    相关资源
    最近更新 更多