import java.sql.*;
import javax.swing.*;
import java.awt.*;
Befor you begion initialize your form:
Connection conn = null;
ResultSet rs = null;
PreparedStatement pst = null;
in your constructor of your form. In this case login
public Login() {
initComponents();
conn = javaconnect.ConnecrDB();
}
when button clicked check for login:
private void cmd_loginActionPerformed(java.awt.event.ActionEvent evt) {
String sql = "select * from users where first_name=? and password=?";
// String sql="select * from Modules where username=? and password=?";
try {
pst = conn.prepareStatement(sql);
pst.setString(1, txt_username.getText());
pst.setString(2, txt_password.getText());
rs= pst.executeQuery();
if (rs.next()) {
JOptionPane.showMessageDialog(null, "Username and Password are correct");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
import javax.swing.*;
import java.awt.*;
Befor you begion initialize your form:
Connection conn = null;
ResultSet rs = null;
PreparedStatement pst = null;
in your constructor of your form. In this case login
public Login() {
initComponents();
conn = javaconnect.ConnecrDB();
}
when button clicked check for login:
private void cmd_loginActionPerformed(java.awt.event.ActionEvent evt) {
String sql = "select * from users where first_name=? and password=?";
// String sql="select * from Modules where username=? and password=?";
try {
pst = conn.prepareStatement(sql);
pst.setString(1, txt_username.getText());
pst.setString(2, txt_password.getText());
rs= pst.executeQuery();
if (rs.next()) {
JOptionPane.showMessageDialog(null, "Username and Password are correct");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
No comments:
Post a Comment