2017-06-12 181 views
1

我試圖做一個登錄代碼。快速的解釋是,我要顯示在deatils頁面的帳戶的詳細信息,但我不能這樣做,因爲錯誤總是顯示該功能沒有在JDBC驅動程序中實現沒有在JDBC驅動程序中實現sqlite

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

有什麼功能?如果有連接,則存在SQLLite驅動程序。不清楚你在問什麼。 – EJP

+0

connDB定義在哪裏? –

+0

顯示錯誤! –

回答

2

最有可能的問題是在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)答案還描述未在SQLite的JDBC驅動實現。

您可以直接使用psts.executeQuery();或分辨率。 psts.executeUpdate();這裏沒有參數,因爲在創建預準備語句時Query已經被定義。

Btw。確保你總是關閉你的PreparedStatement s和ResultSet s。 有關說明,請參見Do I need to close PreparedStatement

相關問題