Form Login
Langkah 1 : Buat form seperti gambar berikut :
Langkah 2 :
Selanjutnya buat table user dengan field seperti pada gambar diatas :
Langkah 3 :
Tambahkan code di bawah ini sesuaikan dengan method dan event dari masing-
masing obyek.
public class frmLogin extends javax.swing.JFrame {
Connection Con;
ResultSet RsUser;
Statement stm;
/** Creates new form frmLogin */
public frmLogin() {
initComponents();
open_db();
}
private void cmdOkActionPerformed(java.awt.event.ActionEvent evt) {
try{
char[] input=txtPassword.getPassword();
String password;
password = new String(txtPassword.getPassword());
stm = Con.createStatement();
RsUser=stm.executeQuery("select * from user where user_id='"+
txtUserId.getText()+"' and password=md5('"+password+"')");
int baris=0;
while(RsUser.next()) {
baris = RsUser.getRow();
}
if(baris==1)
{
JOptionPane.showMessageDialog(null, "User dan Password Cocok");
System.exit(0);
}
else
{
JOptionPane.showMessageDialog(null, "User atau Password tdk
Cocok -> "+txtUserId.getText()+" --> "+password);
}
}
catch(SQLException e){
JOptionPane.showMessageDialog(null, e);
}
}
private void cmdBatalActionPerformed(java.awt.event.ActionEventevt) {
System.exit(0);
}
private void open_db(){
try{
KoneksiMysql kon= new KoneksiMysql ("localhost","root", "root","penjualan");
Con = kon.getConnection();
}
catch (Exception e) {
System.out.println("Error : "+e);
}
}
No comments:
Post a Comment