I have a question - not sure where to post it, but i'll try here.
So I have the following piece of code:
public boolean checkUser(String user, String password){ boolean connected = false; try{ Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection con = DriverManager.getConnection("jdbc:mysql://localhost/finalprojects", "root", "password"); Statement st = con.createStatement(); ResultSet rs = st.executeQuery("select * from users where user ='" + user + "' and password ='" + password +"';"); connected = true; rs.close(); st.close(); return connected; }catch(Exception e){ e.printStackTrace(); } return connected; }
Now what is suppose to happen is you enter (into a form) a user name of say Jake and a password of Jake. this will query the database based on that information and return true IF the user exists with the username and password you entered.
what I need to know is how to say:
Ok so username Jake and password Jake doesn't exist then return false - which then gets passed up to the page and the user is alerted that hey you don't exist. (the passing to the page is done).
What are the steps I need to take to query the database to check for username and password and see if they match that which the user has entered or not.
Because right now if you exist - great - return true. if not - return false.