Posted inServices
String username = JTextFieldl.getText().trim();
String password = String.valueOf(jPasswordFieldl.getPassword());
try{
Connection conn DAO.getConnection();
String sql “SELECT FROM customer WHERE username = ?”;
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, username);
I
ResultSet rs = pstmt.executeQuery(); // run the query
if(rs.next()) {
String db_password=rs.getString(“password”);
if (password.equals(db_password)){
this.dispose();
new MainManue().setVisible(true);
Jelse{
JOptionPane.showMessageDialog(this, “Invalid login, try with
Jelse {
JOptionPane.showMessageDialog(this, “User not found.”);
.
public class DAO {
private static final String URL = “jdbc:mysql://localhost:3306/question3_db”;
private static final String USER = “isthi”;
private static final String PASSWORD = “isthi”;
private static final String DRIVER = “com.mysql.cj.jdbc.Driver”;
public static Connection getConnection() {
try {
Class.forName(DRIVER);
return DriverManager.getConnection(URL, USER, PASSWORD);
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
}
return null;