Created
May 24, 2022 15:16
-
-
Save rapisenpai/87974a15f90bd7c5af3c08b38c447342 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CONNECT LOGIN BUTTON TO DATABASE(MYSQL) | |
1. CREATE A METHOD | |
Connection con; | |
PreparedStatement pst; | |
ResultSet rs; | |
public void Connect() { | |
try { | |
Class.forName("com.mysql.jdbc.Driver"); | |
con = DriverManager.getConnection("jdbc:mysql://localhost:3307/hospitalmanagementsystem", "root", ""); | |
} catch (ClassNotFoundException e) { | |
// TODO Auto-generated catch block | |
Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, e); | |
} catch (SQLException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, e); | |
} | |
} | |
2. ADD THIS TO THE BUTTON | |
String username = txtUsername.getText(); | |
String password = new String(txtPassword.getPassword()); | |
try { | |
pst = con.prepareStatement("SELECT * FROM login"); | |
rs = pst.executeQuery(); | |
while(rs.next()) { | |
String username1 = rs.getString("username"); | |
String password1 = rs.getString("password"); | |
if (username.equals(username1) && (password.equals(password1))) { | |
dashboard.main(null); | |
logInFrame.setVisible(false); | |
} | |
} | |
} catch (SQLException e1) { | |
Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, e1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/rapisenpai/Libraries-MySQLConnector.git