Question: Can you take text that has been input through a textbox assign it to a 'String name;' then take that String call a separate class that actually holds the connection to the MySql database and also the query you want to run and pass it that string value to fulfill a query parameter? Now I know enough that passing values from one class to another is not unusual but it appears that I may be missing a piece to properly pass the string to the query properly.
I am connecting properly so I will not include all of that information:
This is the method that is initially accepting the input from the textbox.
This is just the two methods that I am concerned with at this point. I am looking to simply see how to pass the values properly...since this is not working as it is right now.
I am connecting properly so I will not include all of that information:
Public class Mediator{ public Boolean verifyLogin(String un, String pw){ Boolean compareValue = false; String sql = "select * from users where login_Name = ? and password = ?"; try { pst = conn.prepareStatement(sql); pst.setString(1, un); pst.setString(2, pw); rs = pst.executeQuery(); while (rs.next()) { compareValue = true; //JOptionPane.showMessageDialog(null, "username and password are correct"); //Added this line so when login is successful the StartupScreen.java will initialize. //new StartupScreen().setVisible(true); } } catch (Exception e) { //JOptionPane.showMessageDialog(null, e); } return compareValue; } }
This is the method that is initially accepting the input from the textbox.
public class LoginScreenFrom{} { private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { String userName = username.getText(); String passWord = password.getText(); if (mediator.verifyLogin(userName, passWord)){ // transition to next page } else{JOptionPane.showMessageDialog(null, "Invalid username and password");}
This is just the two methods that I am concerned with at this point. I am looking to simply see how to pass the values properly...since this is not working as it is right now.