Tutorial Login With MySQL In Netbeans

Tutorial Login With MySQL In Netbeans


Hello friend, on this occasion I will discuss a little about how to create a login form using MySQL database. So the login form we will later identify the user's username and password.

First, we open Netbeans first and create a new project. After that we create a connection file as a link. for more details friends can follow the following tutorial:

We start to create a form by right click Package → New → JFrame Form then name it as you want and start designing that consists of several components as follows:
  • 2 Textfield
  • 2 Button
  • 3 Label
more or less the design as shown below:

Next we create 1 Form again as Main Menu so that when the login process will be directly directed to the main menu. Then in the initialization we enter the code so that when the main menu appears, he will appear full screen.

public MenuUtama() {

Now we go back to the Login Form and double-click the Login button and enter the following code:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            Connection c = ClassDB.getkoneksi();
            Statement s = c.createStatement();
            String sql = "select * from users where username = '" + jTextField1.getText().toString() + "' and pwd = '" + jTextField2.getText().toString() +"'";   
            ResultSet r = s.executeQuery(sql);
                MenuUtama menu = new MenuUtama();
                JOptionPane.showMessageDialog(rootPane,"Login Gagal Periksa Username dan Password Anda","Pesan",JOptionPane.WARNING_MESSAGE);    
        }catch(SQLException e){
            JOptionPane.showMessageDialog(rootPane, e);

Similarly with the exit key enter the code below so that when clicked the program will come out:

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {         

When everything is done, the program is ready to run.

For more details, please see the video tutorial below

Powered by Blogger.