Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String sql = "Select * from logindb";
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/studentrecords", "root", "password");
- Statement stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery(sql);
- String user = txtUsername.getText();
- String pwd = new String(txtPassword.getPassword());
- while (rs.next()) {
- String uname = rs.getString("uname");
- //Username is the coloumn name in the database table
- String password = rs.getString("upass");
- if ((user.equals(uname)) && (pwd.equals(password))) {
- MainPage mp = new MainPage();
- mp.setVisible(true);
- dispose();
- } else {
- lblError.setVisible(true);
- }
- }
- }
- catch (Exception e)
- {
- JOptionPane.showMessageDialog(this, e.getMessage());
- }
- String query = "Select * from studentinfo";
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- //connection
- Connection conn = (Connection)
- //root and username and password for access to the database
- DriverManager.getConnection("jdbc:mysql://localhost:3306/studentdb","root","");
- //create the statement that will be used
- Statement stmt=conn.createStatement();
- ResultSet rs = stmt.executeQuery(query);
- String user = txtUsername.getText();
- String pwd = new String(txtPassword.getPassword());
- while(rs.next())
- {
- String uname = rs.getString("uname");
- //Username is the coloumn name in the database table
- String password = rs.getString("upass");
- if ((user.equals(uname)) && (pwd.equals(password))) {
- MainPage mp = new MainPage();
- mp.setVisible(true);
- dispose();
- }
- else
- {
- lblError.setVisible(true);
- }
- }
- }
- catch(Exception e)
- {
- JOptionPane.showMessageDialog(null, "Username or password was incorrect, please try again.", "LOGIN ERROR", JOptionPane.ERROR_MESSAGE);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement