Database can make directly from phpMyAdmin or could open with NetBeans IDE that of phpMyAdmin for database first, here database name “dbperkuliahan” and the name of the table “tblogin”. Create as shown below:
after created the database just open his Netbeans select file New ProjectJavaJava user application so that the following picture emerges:
and then click next
Fill the Project Name > log and remove the check mark in the Create Main Class and Set as Main
Project and click Finish.
it will appear as shown below:
right click-> new->Jfram form will appear
design form
Libraries–>add library–>MySQL JDBC Driver
Create new package : A right click on the Source Packages then select New Java Package fill package name with “koneksi” and then press Finish (see figure below):
Start coding
JTextField1 variable name change to = tnama
JTextField2 variable name change to = tpas
in koneksi class conek type this scrip :
package koneksi; import com.mysql.jdbc.Driver; import java.sql.DriverManager; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException;
public class conek { private static Connection koneksi;
public static Connection GetConnection()throws SQLException{ if (koneksi==null){ new Driver(); koneksi=DriverManager.getConnection(“jdbc:mysql://localhost:3306/dbperkuliahan”,”root”,””);
} return koneksi;
}
}
Then in the class form login typing this scrip :
import com.mysql.jdbc.Connection; import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
import koneksi.conek;
public class Login extends javax.swing.JFrame { /** * Creates new form Login */ public Login() { initComponents();}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { try { Statement statement = (Statement) conek.GetConnection().createStatement(); ResultSet result=statement.executeQuery(“select * from tblogin where ” + “username='” + tnama.getText() + “‘”);
if (result.next()) { if (tpas.getText().equals(result.getString(“password”))) { new MenuUtama().show();
this.dispose(); }
else { JOptionPane.showMessageDialog(rootPane, “wrong password”); tpas.setText(“”);
tnama.requestFocus(); } }
else { JOptionPane.showMessageDialog(rootPane, “user not found”);
tnama.setText(“”)
tpas.setText(“”);
tnama.requestFocus(); } } catch (Exception e) { JOptionPane.showMessageDialog(rootPane, “fail”); }
// TODO add your handling code here:
}
// jbutton1 untuk login private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { this.dispose();
//jbutton2 for cancel. start the program. good luck