java - Unable to test username/password with JDBC query -


I am trying to create a login form that connects to a SQL database. Here is my code:

  Private Zero CMD_Login ActionPerform (Java.av.te.Event.Ection EventEVT) {String SQL = "Inventor 1 to Sealette;"; Try {class.forName ("com.mysql.jdbc.Driver"); Connection conn = (connection); DriverManager.getConnection ("JDBC: mysql: // local host: 3306 / inventor", "root", "root"); Statement stmt = conn.createStatement (); Results set rs = stmt.executeQuery (SQL); Letter user = t1.getText (); String pass = new string (t2.getText ()); While (rs.next ()) {string user name = rs.getString ("user name"); String password = rs.getString ("password"); If (user.equals ("user name") & amp; amp; pass.equals ("password")) {new mainmenu (). SetVisible (true); }}} Hold (exception e) {JOptionPane.showMessageDialog (this is not "password and username match"); }}  

Although the user and password never match, even if whatever I entered, what happens in the database. Why does not a username and password match?

First of all Typos (should be)

to
  • connection conn = (connection); & Lt; ---- Remove;
  • Now you may be getting exception , but you're swallowing it using

     < Code> JoyptionPan. ShmosezialDiooge (This is, "password and username not match");  

    So I think the reason for this problem is your query which is throwing every time due to SQLException to Selet .

    The other you are retrieving all data using the * I think that only two columns in your table are okay with username and password, but in programming In fact, it is a good practice to be more specific in your code.


    Comments

    Popular posts from this blog

    java - org.apache.http.ProtocolException: Target host is not specified -

    java - Gradle dependencies: compile project by relative path -

    ruby on rails - Object doesn't support #inspect when used with .include -