Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- *//*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package rentalmobil.karyawan;
- import java.sql.*;
- import javax.swing.JOptionPane;
- /**
- *
- * @author surya
- */
- public class FormLOGINKARYAWAN extends javax.swing.JFrame {
- Connection con;
- Statement stt;
- ResultSet rss;
- /**
- * Creates new form FormLOGINUSER
- */
- public FormLOGINKARYAWAN() {
- initComponents();
- Koneksi();
- }
- public void Koneksi(){
- try{
- Class.forName("com.mysql.jdbc.Driver");//1. Load Driver
- String database = "jdbc:mysql://localhost:3306/rental_mobil";//2. Memanggil alamat database
- String userDtbs = "root";//username default database
- String passDtbs = "";//password default database
- con = DriverManager.getConnection(database,userDtbs,passDtbs);//3. Membuat Koneksi Database
- stt = con.createStatement();//membuat statement
- }
- catch(Exception e){
- JOptionPane.showMessageDialog(null,"Gagal Koneksi","Pesan",JOptionPane.ERROR_MESSAGE);
- }
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- inputuser = new javax.swing.JTextField();
- inputpass = new javax.swing.JPasswordField();
- cmdlogin = new javax.swing.JButton();
- jLabel1 = new javax.swing.JLabel();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setTitle("LOGIN USER");
- jLabel2.setText("Username");
- jLabel3.setText("Password");
- cmdlogin.setText("Login");
- cmdlogin.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- cmdloginActionPerformed(evt);
- }
- });
- jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
- jLabel1.setText("LOGIN");
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel2)
- .addComponent(jLabel3))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel1)
- .addComponent(cmdlogin)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(inputuser)
- .addComponent(inputpass, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jLabel1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel2)
- .addComponent(inputuser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel3)
- .addComponent(inputpass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addComponent(cmdlogin)
- .addContainerGap())
- );
- pack();
- }// </editor-fold>
- private void cmdloginActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- try{
- String sql = "SELECT * FROM tbuser WHERE username = '"+inputuser.getText()+"' and password = '"+String.valueOf(inputpass.getPassword())+"'";
- rss = stt.executeQuery(sql);
- if(rss.next()){
- String user = rss.getString(1);
- String password = rss.getString(2);
- JOptionPane.showMessageDialog(null, "Berhasil Login");
- new MainMENUKARYAWAN().show();
- this.dispose();
- }else{
- JOptionPane.showMessageDialog(null, "Gagal Login","Pesan",JOptionPane.ERROR_MESSAGE);
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(FormLOGINKARYAWAN.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(FormLOGINKARYAWAN.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(FormLOGINKARYAWAN.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(FormLOGINKARYAWAN.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new FormLOGINKARYAWAN().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton cmdlogin;
- private javax.swing.JPasswordField inputpass;
- private javax.swing.JTextField inputuser;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement