Note that there are some explanatory texts on larger screens.

plurals
  1. POJDBC always tests the last row of MySQL table?
    primarykey
    data
    text
    <p>I have a Manager class that saves data in the SQL table and also get result from SQL table and test these data.when I run my program,one frame will be shown that gets ID and password and if they are correct ,the other frame will be shown.BUT I don't know that why it just test the last row of SQL table?? i mean if I set those text fields with the other IDs and passwords except from last row.it will show the data are wrong(I have set it before for wrong data)</p> <p>Manager class:</p> <pre><code> public static boolean Test(String userName, String password) { boolean bool = false; Statement stmt = null; try { stmt = conn.createStatement(); ResultSet rst = null; rst = stmt.executeQuery("SELECT yahooId , password FROM clienttable"); while (rst.next()) { if (rst.getString(1).equalsIgnoreCase(userName) &amp;&amp; rst.getString(2).equalsIgnoreCase(password)) { bool = true; } else { bool = false; } } } catch (SQLException ex) { Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, null, ex); } return bool; } </code></pre> <p>my button's perform action in the frame which get the ID and password and test it:</p> <pre><code> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { try { submit(); } catch (ConnectException ex) { JOptionPane.showMessageDialog(this, "You coudn't connect to the server successfully,try it again", "Sign_In Problem", JOptionPane.OK_OPTION); } clear(); } private void submit() throws ConnectException { String id = idField.getText(); char[] pass1 = passField.getPassword(); String pass = new String(pass1); if (id.equals("") || pass.equals("")) { Toolkit.getDefaultToolkit().beep(); JOptionPane.showMessageDialog(this, "You should enter an ID and password", "Sign_In Problem", JOptionPane.OK_OPTION); return; } else { boolean b = Manager.Test(id, pass); client.setCurrentName(id); if (b == true) { this.setVisible(false); ListFrame frame = new ListFrame(client); frame.setVisible(true); } else { JOptionPane.showMessageDialog(this, "You have entered wrong datas,try it again", "Sign_In Problem", JOptionPane.OK_OPTION); return; } } } </code></pre> <p>EDIT:</p> <p>I have edited my manager class(test method) but still it works like past!!</p> <pre><code> public static boolean Test(String userName, String password) { boolean bool = false; PreparedStatement stmt = null; ResultSet resultSet = null; try { stmt = conn.prepareStatement("SELECT id FROM clienttable WHERE yahooId = ? AND password = ?"); stmt.setString(1, userName); stmt.setString(2, password); resultSet = stmt.executeQuery(); bool = resultSet.next(); } catch (SQLException ex) { Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, null, ex); } finally { try { resultSet.close(); stmt.close(); conn.close(); } catch (SQLException ex) { Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, null, ex); } } return bool; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload