Jumat, 05 April 2019

Codingan login menggunakan hak akses

  • Pertama Kalian Harus Membuat database terlebih dahulu seperti dibawah ini :

  • tb_level


  • tb_user




  • Setelah itu baru kalian membuat Fromnya diNetbeans



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package restoran;

import java.sql.*;
import javax.swing.JOptionPane;
import restoran.inc.config_restoran;

/**
 *
 * @author LAB_RPL
 */
public class login extends javax.swing.JFrame {
Connection conn;
    ResultSet rs;
    PreparedStatement pst;
    Statement st;
    /**
     * Creates new form login
     */
    public login() {
        initComponents();
    }
     public void cek(){
        conn = config_restoran.KoneksiDb();
     
        try {
            st = conn.createStatement();
            String sql = "SELECT * FROM tb_user where username = '"+txUser.getText()+"' and password = '"+txPass.getText()+"'";
            rs = st.executeQuery(sql);
         
            if(rs.next()){
                if(rs.getString("id_level").equals("1")){
                    menu fa = new menu();
                    fa.show();
                    this.dispose();
                }else if(rs.getString("id_level").equals("2")){
                    waiter fu = new waiter();
                    fu.show();
                    this.dispose();
                }
                else if(rs.getString("id_level").equals("3")){
                    kasir fu = new kasir();
                    fu.show();
                    this.dispose();
                }
                else if(rs.getString("id_level").equals("4")){
                    owner fu = new owner();
                    fu.show();
                    this.dispose();
                }
                else if(rs.getString("id_level").equals("5")){
                    pelanggan fu = new pelanggan();
                    fu.show();
                    this.dispose();
                }
            }else{
                JOptionPane.showMessageDialog(null, "Maaf password atau username anda salah");
                txUser.setText("");
                txPass.setText("");
                txUser.requestFocus();
            }
        }catch(SQLException e){
            JOptionPane.showMessageDialog(null, e);
        }
     }


private void loginActionPerformed(java.awt.event.ActionEvent evt) {                                   
        // TODO add your handling code here:
       cek();
    }                                   

    private void keluarActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
        System.exit(0);
    }       









SELESAI SELAMAT MENCOBA !!!

Contoh codingan untuk Transaksi pada NetBeans

Contoh Codingan untuk Transaksi pada NetBeans /*  * To change this license header, choose License Headers in Project Properties. ...