title: SQLite Log-In Check username & password
body: <p>I am creating an Application (Using Java &amp; SQLite)(JFrame, using Netbeans) I have users who I want to log in. (I have all the correct packages JDBC, SQLite etc)</p>
  
  <p>The issue I am having seems to be getting the username/password to check against my users.db file.. I am using Java and SQLite. I'm using JDBC also.</p>
  
  <p>Some of my code as an example (This sends my users information to make the account, Works fine), my database is users.db and I want to compare username/password against USERNAME &amp; PASSWORD</p>
  
  <pre><code>Connection dbconn = null;
  Statement stmt = null;
  String query = "insert into USERS(ID, FIRSTNAME, SECONDNAME, USERNAME, PASSWORD, JAVALESSON, CLESSON, PYTHONLESSON) values(?, ?, ?, ?, ?, ?, ?, ?)";
  
  try {
      Class.forName("org.sqlite.JDBC");
      dbconn = DriverManager.getConnection("jdbc:sqlite:users.db");
      Statement statement = dbconn.createStatement();
      PreparedStatement pstmt = dbconn.prepareStatement(query);
  </code></pre>
  
  <p>I have a UsernameLoginBox &amp; PasswordLoginBox, How would I check USERNAME &amp; PASSWORD (From SQLite Database) against the string in the textbox's for log in?</p>
  
  <p>TRIED CODE:</p>
  
  <pre><code>    Connection conn = null;
      ResultSet rs =null;
      PreparedStatement pst =null;
      String sql1 = "Select * from USERS where USERNAME=? and PASSWORD=?";
      try{
      pst = conn.prepareStatement(sql1);
      pst.setString(1, UsernameLogIn.toString());
      pst.setString(2, PasswordLogInField.getText());
  
          rs=pst.executeQuery();
          if(rs.next()){
          JOptionPane.showMessageDialog(null, "Username &amp; Password are correct");
  
          } else {
              JOptionPane.showMessageDialog(null, "Username &amp; Password are incorrect");
              System.out.println("Logged in");
          }
      }
      catch(Exception e){
  
          JOptionPane.showMessageDialog(null, e);
          System.out.println("Not Logged in");
      }
  </code></pre>
  
  <p>And this:</p>
  
  <pre><code>    Connection cbconn = null;
      Statement stmt2 = null;
  
      String upcheck  = "SELECT USERNAME, PASSWORD FROM USERS";
          ResultSet rs = Statement.executeQuery(upcheck);
  
          while (results.next()) {
          String staffname = results.getString("snameeee");
          String password =  results.getString("SPwd");
  
             if ((f.equals(staffname)) &amp;&amp; (s.equals(password))) {
  
                JOptionPane.showMessageDialog(null, "Username and Password exist");  
          }else {
  
           //JOptionPane.showMessageDialog(null, "Please Check Username and Password ");
          }
          results.close();
      } catch (SQLException sql) {
  
          out.println(sql);
  </code></pre>