Hi all readers, this project we will create a database program using Netbeans IDE 6.5 Database and Ms.Access. Software may Netbeans is new for us. Yes the actual program Netbeans is a software used to create a program based on JAVA. We still use the first appearance of white Notepad to create JAVA applications. Akan NotePad but parallel development is replaced by slow start because TEXTPAD facilities provided by this TEXTPAD seems more complete and informative than the notepad. But when we look kebelakang shortages have appeared TEXTPAD again, that is we still have to type the script to make the program components. And that lack is covered by the Netbeans this. Namely to provide component parts without having to type the script to make the withdrawal other GUI Programming Languages. You can create our new project, we:
Here the view that the program will be created:
The Steps:
***> Create database tables and cooperation with the Member as follows:
==================================================================
Noang - Text - 5
Nama - Text - 25
Alamat - Text - 30
Jkel - Yes/no
Agama - Text - 1
NoKTP - Text - 15
NoTelp - Text - 12
Simpanan - Number - LongInt
============================================================1. Create a design form as shown in the picture. In the form there is a component JTextField, JComboBox, JRadioButton, JPanel, JButton.
2. Change the name of the components that we have entered, especially for components JTextField, JComboBox, JButton, JRadioButton engan way and conditions as follows:
Component Component Name Changes
JTextField No Anggota — no
JTextField Nama — nama
JTextField Alamat — alamat
JComboBox Agama — agama
JRadioButton Jkel — RPria dan RWanita
JTextField No KTP — noktp
JTextField No. Telp — notelp
JTextField Simpanan — simpanan
JButton Simpan — bsimpan
JButton Data Baru — bbaru
JButton Keluar — bkeluar
3. After you change the name of each component so it's time to process incoming Coding.
Program Code:
- Below the tab name of your project, click the source:
Under the package type you import the following command to retrieve the sql commands.
=======================================================
import java.sql;
=======================================================
- The declaration of a variable connection, resultset, statement and the other variables that are required
Public under the following class type variables;
=======================================================
//deklarasi variabel global
Connection Con;
ResultSet RsAng;
Statement StatAng;
//variabel for agama
String sagm = “1″;
//variabel for jenis kelamin
Boolean bjkel = true;
//variabel global where data ditemukan
Boolean ada = false;
- Then, under public nama_project (under the introduction of a variable) type the command database connection and table below:
//connection
try
{
String fdata = “z:\\java1\\NetBeans\\Koperasi.mdb”;
Class.forName(”sun.jdbc.odbc.JdbcOdbcDriver”);
// direct connection to the database without dsn
Con= DriverManager.getConnection(”jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=” + fdata);
//shows the search process can be in the resultset update
StatAng= Con.createStatement( RsAng.TYPE_SCROLL_SENSITIVE, RsAng.CONCUR_UPDATABLE );
RsAng = StatAng.executeQuery(”Select* from Anggota”);
}
catch(Exception e)
{ System.err.println(”Conection error !” + e.getMessage()); } //getMessage to display the message
- After the connection is successful then the time we go to the key store. Type the following code:
================================================== ====
private void bsimpanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try
{
RsAng.updateString(”Noang”, no.getText());
RsAng.updateString(”Nama”, nama.getText());
RsAng.updateString(”Alamat”, alamat.getText());
RsAng.updateString(”Agama”, sagm);
RsAng.updateBoolean(”Jkel”, bjkel);
RsAng.updateString(”NoKTP”, noktp.getText());
RsAng.updateString(”NoTelp”, notelp.getText());
RsAng.updateDouble(”Simpanan”, Double.parseDouble(simpanan.getText()));
if(ada)
{
//mengedit data yang sudah ada
RsAng.updateRow();
javax.swing.JOptionPane.showMessageDialog(null, “Data Telah Diedit !”);
}
else
//menyisipkan record baru
RsAng.insertRow();
javax.swing.JOptionPane.showMessageDialog(null, “Data Telah Tersimpan !”);
}
catch(Exception e)
{
javax.swing.JOptionPane.showMessageDialog(null, “Data Belum Tersimpan !” + e.getMessage());
}
}
======================================================- Code Programs for RadioButton Male:
======================================================
private void RPriaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
bjkel = true;
}
======================================================- Code Programs for Women's RadioButton:
======================================================
private void RWanitaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
bjkel = false;
}
=====================================================- To type a ComboBox in the code the program:
=====================================================
private void agamaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// Baca Source objectnya masih JcomboBox
javax.swing.JComboBox soagama = (javax.swing.JComboBox)evt.getSource();
//Membaca Item Yang Terpilih — > String
String sagama = (String)soagama.getSelectedItem();
//pengujian sagama
if (sagama.equals(”Islam”))
sagm = “1″;
else if (sagama.equals(”Kristen”))
sagm = “2″;
else if (sagama.equals(”Hindhu”))
sagm = “3″;
else if (sagama.equals(”Budha”))
sagm = “4″;
else if (sagama.equals(”Konghu Chu”))
sagm = “5″;
}
==========================================================================================================
private void bbaruActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
no.setText(”");
nama.setText(”");
alamat.setText(”");
noktp.setText(”");
notelp.setText(”");
simpanan.setText(”");
}
=====================================================- To Exit Button component type in the code the program:
=====================================================
private void bkeluarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//Tutup Koneksi
try
{
Con.close();
RsAng.close();
StatAng.close();
Con = null; RsAng = null; StatAng = null;
}
catch (Exception e){}
System.exit(0);
}
====================================================Additional notes (rusted Bos)
- To fill the ComboBox religion you click on the ComboBox component on the properties and religious search model, then click the dialog box will appear as follows:
Post a Comment