1. Seperti biasa kita mulai mengaktifkan aplikasi xampp terlebih dahulu, dan kita aktifkan mysql dan apache :
2. Selanjutnya kita membuat database pada localhost, disini saya beri nama uas dan tabelnya ada login, entry, karyawan.
- Isi tabel Login :
- Isi tabel entry :
- Isi tabel karyawan :
3. Dan setelah database nya beres kita lanjut ke aplikasi Netbeans, bikin project seperti biasa dan jgn lupa untuk di connect kan pada database yang telah kita buat tadi. Tambahkan juga Mysql driver pada library. Pertama saya bikin form Login :
Code :
4. Selanjtya saya bikin form menu utama :
- Code untuk ke form entry buku :
- Code untuk ke form data karyawan :
- Code untuk ke form about :
5. Lalu kita masuk membuat form entry data buku :
- Code button new :
- Code button refresh :
- Code button save :
- Code button change :
- Code button search :
- Code button delete :
- Code button Cancel :
- Code button Exit :
6. Setelah kembali pada menu utama kita lanjut membuat form data karyawan :
- Code button save :
- Code button change :
- Code button delete :
7. Setelah itu saya bikin form about yg isinya visi dan misi :
Source code :
Login :
private void loginActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String username = nama.getText();
String password = pass.getText();
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/uas","root","");
Statement stat = conn.createStatement();
ResultSet RsUser = stat.executeQuery("SELECT * FROM login WHERE Ussername="+"'"+username+"'"+"and Password='"+password+"'");
System.out.println("Alhamdulillah !!");
if (RsUser.next()){
JOptionPane.showMessageDialog(null, "Success","Informasi", JOptionPane.INFORMATION_MESSAGE);
this.dispose();
new mu().show();
}
else {
JOptionPane.showMessageDialog(null, "Sorry, Username or Password are incorect","Informasi", JOptionPane.INFORMATION_MESSAGE);
nama.setText("");
pass.setText("");
nama.requestFocus();
}
}
catch(Exception e){
JOptionPane.showMessageDialog(null, "Failed, please try again","Informasi", JOptionPane.INFORMATION_MESSAGE);
}
}
Menu utama :
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
new entry().setVisible(true);
this.dispose();
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
new karyawan().setVisible(true);
this.dispose();
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
new about().setVisible(true);
this.dispose();
}
entry :
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
/*
* 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.
*/
/**
*
* @author Chitham
*/
public class entry extends javax.swing.JFrame {
/**
* Creates new form entry
*/
public entry() {
initComponents();
}
/**
* 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() {
kodeBukuLabel = new javax.swing.JLabel();
judulLabel = new javax.swing.JLabel();
pengarangLabel = new javax.swing.JLabel();
penerbitLabel = new javax.swing.JLabel();
jenisLabel = new javax.swing.JLabel();
tahunTerbitLabel = new javax.swing.JLabel();
kategoriLabel = new javax.swing.JLabel();
hargaBeliLabel = new javax.swing.JLabel();
diskonLabel = new javax.swing.JLabel();
hargaPokokLabel = new javax.swing.JLabel();
hargaJualLabel = new javax.swing.JLabel();
stockLabel = new javax.swing.JLabel();
kode = new javax.swing.JTextField();
judul = new javax.swing.JTextField();
pengarang = new javax.swing.JTextField();
penerbit = new javax.swing.JTextField();
jenis = new javax.swing.JComboBox();
tahun = new javax.swing.JTextField();
kategori = new javax.swing.JComboBox();
hbeli = new javax.swing.JTextField();
diskon = new javax.swing.JTextField();
hpokok = new javax.swing.JTextField();
hjual = new javax.swing.JTextField();
stock = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
newButton = new javax.swing.JButton();
delete = new javax.swing.JButton();
refreshButton = new javax.swing.JButton();
saveButton = new javax.swing.JButton();
change = new javax.swing.JButton();
cancel = new javax.swing.JButton();
exit = new javax.swing.JButton();
cari = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
kodeBukuLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
kodeBukuLabel.setText("Kode Buku:");
getContentPane().add(kodeBukuLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(46, 153, -1, -1));
judulLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
judulLabel.setText("Judul:");
getContentPane().add(judulLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(46, 183, -1, -1));
pengarangLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
pengarangLabel.setText("Pengarang:");
getContentPane().add(pengarangLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(46, 213, -1, -1));
penerbitLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
penerbitLabel.setText("Penerbit:");
getContentPane().add(penerbitLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(46, 243, -1, -1));
jenisLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
jenisLabel.setText("Jenis:");
getContentPane().add(jenisLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(46, 273, -1, -1));
tahunTerbitLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
tahunTerbitLabel.setText("Tahun Terbit:");
getContentPane().add(tahunTerbitLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(42, 303, -1, -1));
kategoriLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
kategoriLabel.setText("Kategori:");
getContentPane().add(kategoriLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(46, 333, -1, -1));
hargaBeliLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
hargaBeliLabel.setText("Harga Beli:");
getContentPane().add(hargaBeliLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(46, 363, -1, -1));
diskonLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
diskonLabel.setText("Diskon:");
getContentPane().add(diskonLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(589, 273, -1, -1));
hargaPokokLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
hargaPokokLabel.setText("Harga Pokok:");
getContentPane().add(hargaPokokLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(589, 303, -1, -1));
hargaJualLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
hargaJualLabel.setText("Harga Jual:");
getContentPane().add(hargaJualLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(589, 333, -1, -1));
stockLabel.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
stockLabel.setText("Stock:");
getContentPane().add(stockLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(589, 363, -1, -1));
kode.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
kode.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
kodeFocusLost(evt);
}
});
kode.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
kodeActionPerformed(evt);
}
});
getContentPane().add(kode, new org.netbeans.lib.awtextra.AbsoluteConstraints(136, 150, 100, -1));
judul.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
getContentPane().add(judul, new org.netbeans.lib.awtextra.AbsoluteConstraints(136, 180, 300, -1));
pengarang.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
getContentPane().add(pengarang, new org.netbeans.lib.awtextra.AbsoluteConstraints(136, 210, 400, -1));
penerbit.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
getContentPane().add(penerbit, new org.netbeans.lib.awtextra.AbsoluteConstraints(136, 240, 300, -1));
jenis.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
jenis.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Pilih", "Novel", "Cergam", "Komik", "Nomik", "Antologi (kumpulan)", "Dongeng", "Biografi", "Catatan harian (jurnal/diary)", "Novelet", "Fotografi", "Karya ilmiah", "Tafsir", "Kamus", "Panduan (how to)", "Atlas", "Ilmiah", "Teks", "Mewarnai" }));
jenis.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jenisActionPerformed(evt);
}
});
getContentPane().add(jenis, new org.netbeans.lib.awtextra.AbsoluteConstraints(136, 270, 100, -1));
tahun.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
getContentPane().add(tahun, new org.netbeans.lib.awtextra.AbsoluteConstraints(136, 300, 100, -1));
kategori.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
kategori.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Pilih", "Agama", "Aksesoris Kado & Parcel", "Anak-Anak", "Bahasa dan Kamus", "Biografi dan Memoar", "Buku Import Teknik dan Design", "Buku Novel", "Buku Sekolah", "Buku Teks", "Busana dan Kecantikan", "CD Pembelajaran Interaktif", "EBook", "Ekonomi dan Manajemen", "Hobi dan Usaha", "Hukum dan Undang-undang", "Humor", "Inspirasi dan Spiritual", "Kesehatan dan Lingkungan", "Komik", "Komputer dan Internet", "Majalah", "Masakan dan Makanan", "Non-Fiksi Lainnya", "Orang Tua dan Keluarga", "Perhotelan dan Pariwisata", "Produk lainnya", "Psikologi dan Pengembangan Diri", "Referensi", "Remaja", "Sains dan Teknologi", "Sastra dan Filsafat", "Sejarah dan Budaya", "Teknik", "Tjersil-Buku Cerita Silat" }));
getContentPane().add(kategori, new org.netbeans.lib.awtextra.AbsoluteConstraints(136, 330, 100, -1));
hbeli.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
getContentPane().add(hbeli, new org.netbeans.lib.awtextra.AbsoluteConstraints(136, 360, 100, -1));
diskon.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
diskon.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
diskonFocusLost(evt);
}
});
getContentPane().add(diskon, new org.netbeans.lib.awtextra.AbsoluteConstraints(694, 270, 30, -1));
hpokok.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
getContentPane().add(hpokok, new org.netbeans.lib.awtextra.AbsoluteConstraints(694, 300, 100, -1));
hjual.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
getContentPane().add(hjual, new org.netbeans.lib.awtextra.AbsoluteConstraints(693, 330, 101, -1));
stock.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
getContentPane().add(stock, new org.netbeans.lib.awtextra.AbsoluteConstraints(693, 360, 101, -1));
jLabel1.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
jLabel1.setText("%");
getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(728, 273, -1, -1));
newButton.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
newButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/plus.png"))); // NOI18N
newButton.setText("New");
newButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
newButtonActionPerformed(evt);
}
});
getContentPane().add(newButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(589, 421, 96, -1));
delete.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
delete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/x.png"))); // NOI18N
delete.setText("Delete");
delete.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
deleteActionPerformed(evt);
}
});
getContentPane().add(delete, new org.netbeans.lib.awtextra.AbsoluteConstraints(703, 454, -1, -1));
refreshButton.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
refreshButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/refresh.jpg"))); // NOI18N
refreshButton.setText("Refresh");
refreshButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
refreshButtonActionPerformed(evt);
}
});
getContentPane().add(refreshButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(588, 454, -1, -1));
saveButton.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
saveButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/save.png"))); // NOI18N
saveButton.setText("Save");
saveButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
saveButtonActionPerformed(evt);
}
});
getContentPane().add(saveButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(588, 492, 99, -1));
change.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
change.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/ganti.jpg"))); // NOI18N
change.setText("Change");
change.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
changeActionPerformed(evt);
}
});
getContentPane().add(change, new org.netbeans.lib.awtextra.AbsoluteConstraints(588, 530, 99, -1));
cancel.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
cancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/batal.png"))); // NOI18N
cancel.setText("Cancel");
cancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelActionPerformed(evt);
}
});
getContentPane().add(cancel, new org.netbeans.lib.awtextra.AbsoluteConstraints(703, 492, 91, -1));
exit.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
exit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/exit.jpg"))); // NOI18N
exit.setText("Exit");
exit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitActionPerformed(evt);
}
});
getContentPane().add(exit, new org.netbeans.lib.awtextra.AbsoluteConstraints(703, 530, 91, -1));
cari.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
cari.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/search.jpg"))); // NOI18N
cari.setText("Search");
cari.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cariActionPerformed(evt);
}
});
getContentPane().add(cari, new org.netbeans.lib.awtextra.AbsoluteConstraints(703, 421, -1, -1));
jButton1.setFont(new java.awt.Font("Comic Sans MS", 0, 12)); // NOI18N
jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/home-.jpg"))); // NOI18N
jButton1.setText("Home");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(46, 530, -1, -1));
jLabel2.setFont(new java.awt.Font("Comic Sans MS", 1, 24)); // NOI18N
jLabel2.setText("D'brilliant Bookstore");
getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 20, -1, -1));
jLabel4.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
jLabel4.setText("Jl. Siaga Raya No.15 Pejaten barat, Pasar Minggu Jakarta Selatan. Telp : (021) 387654 ");
getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 60, -1, -1));
jLabel3.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
jLabel3.setText("Website: www.dbrilliantbookstore.com email: dbrilliantbookstore@gmail.com");
getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 80, -1, -1));
jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/2000-Header.png"))); // NOI18N
getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 840, 120));
jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/24374063-seamless-vertical-stripes-pattern-Stock-Vector-blue-background-striped.jpg"))); // NOI18N
getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 120, 850, 480));
pack();
setLocationRelativeTo(null);
}// </editor-fold>
private void kodeFocusLost(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
}
private void kodeActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void diskonFocusLost(java.awt.event.FocusEvent evt) {
// TODO add your handling code here:
}
private void exitActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (JOptionPane.showConfirmDialog(null,
"Are you sure want to exit ?","Confirmation",
JOptionPane.YES_NO_OPTION)==
JOptionPane.YES_OPTION){
System.exit(WIDTH);
}
}
private void cancelActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
private void changeActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int bismillah=JOptionPane.showConfirmDialog(null,"Are you sure want to edit?","Confirmation",JOptionPane.YES_NO_OPTION);
try{
Class.forName("com.mysql.jdbc.Driver");
Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/uas", "root", "");
Statement stat=connection.createStatement();
String sqlnya="update entry set kode_buku=?,judul=?,pengarang=?,penerbit=?,jenis=?,tahun_terbit=?,kategori=?,harga_beli=?,diskon=?,harga_pokok=?,harga_jual=?,stock=? where "
+ "kode_buku='"+kode.getText()+"'";
PreparedStatement st=connection.prepareStatement(sqlnya);
if(bismillah==0){
try{
st.setString(1,kode.getText());
st.setString(2,judul.getText());
st.setString(3,pengarang.getText());
st.setString(4,penerbit.getText());
st.setString(5, (String) jenis.getSelectedItem());
st.setString(6,tahun.getText());
st.setString(7, (String) kategori.getSelectedItem());
st.setString(8,hbeli.getText());
st.setString(9,diskon.getText());
st.setString(10,hpokok.getText());
st.setString(11,hjual.getText());
st.setString(12,stock.getText());
st.executeUpdate();
JOptionPane.showMessageDialog(null,"Update Succesed");
}catch (Exception e){
JOptionPane.showMessageDialog(null, "Update Failed"+e);
}
}
}catch (Exception e){}
}
private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
Class.forName("com.mysql.jdbc.Driver");
Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/uas", "root", "");
Statement stat=connection.createStatement();
String sqlnya="INSERT INTO entry VALUES ('"+kode.getText()+"','"+judul.getText()+"','"+pengarang.getText()+"',"
+ "'"+penerbit.getText()+"','"+jenis.getSelectedItem()+"','"+tahun.getText()+"','"+kategori.getSelectedItem()+"','"+hbeli.getText()+"',"
+ "'"+diskon.getText()+"','"+hpokok.getText()+"','"+hjual.getText()+"','"+stock.getText()+"')";
PreparedStatement ps=connection.prepareStatement(sqlnya);
stat.executeUpdate(sqlnya);
JOptionPane.showMessageDialog(rootPane, "Succes");
}catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, "Connection failed "+e);
}
}
private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
kode.setText("");
judul.setText("");
pengarang.setText("");
penerbit.setText("");
jenis.setSelectedItem("Pilih");
tahun.setText("");
kategori.setSelectedItem("Pilih");
hbeli.setText("");
diskon.setText("");
hpokok.setText("");
hjual.setText("");
stock.setText("");
}
private void deleteActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String x=JOptionPane.showInputDialog(null, "Please Enter the code");
try {
Class.forName("com.mysql.jdbc.Driver");
Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/uas", "root", "");
Statement stat=connection.createStatement();
String del="DELETE FROM entry WHERE kode_buku='"+x+"'";
stat.executeUpdate(del);
JOptionPane.showMessageDialog(rootPane, "Deleted");
kode.setText("");
judul.setText("");
pengarang.setText("");
penerbit.setText("");
jenis.setSelectedItem("");
tahun.setText("");
kategori.setSelectedItem("");
hbeli.setText("");
diskon.setText("");
hpokok.setText("");
hjual.setText("");
stock.setText("");
}catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, "Connection failed");
}
}
private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
kode.setText("");
judul.setText("");
pengarang.setText("");
penerbit.setText("");
jenis.setSelectedItem("");
tahun.setText("");
kategori.setSelectedItem("");
hbeli.setText("");
diskon.setText("");
hpokok.setText("");
hjual.setText("");
stock.setText("");
}
private void jenisActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void cariActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String x=JOptionPane.showInputDialog(null, "Please enter the code");
try {
Class.forName("com.mysql.jdbc.Driver");
Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/uas", "root", "");
Statement stat=connection.createStatement();
String cari="SELECT * FROM entry WHERE kode_buku='"+x+"'";
ResultSet rsnya= stat.executeQuery(cari);
if (rsnya.next()){
System.out.print(rsnya.getString(1));
kode.setText(rsnya.getString(1));
judul.setText(rsnya.getString(2));
pengarang.setText(rsnya.getString(3));
penerbit.setText(rsnya.getString(4));
jenis.setSelectedItem(rsnya.getString(5));
tahun.setText(rsnya.getString(6));
kategori.setSelectedItem(rsnya.getString(7));
hbeli.setText(rsnya.getString(8));
diskon.setText(rsnya.getString(9));
hpokok.setText(rsnya.getString(10));
hjual.setText(rsnya.getString(11));
stock.setText(rsnya.getString(12));
JOptionPane.showMessageDialog(rootPane, "Found");
}else{
JOptionPane.showMessageDialog(rootPane, "Not Found");
}
}catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, "Connection Failed"+e);
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
new mu().setVisible(true);
this.dispose();
}
data karyawan :
private void saveActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
Class.forName("com.mysql.jdbc.Driver");
Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/uas", "root", "");
Statement stat=connection.createStatement();
String sqlnya="INSERT INTO karyawan VALUES ('"+id.getText()+"','"+nama.getText()+"','"+jabatan.getText()+"',"
+ "'"+alamat.getText()+"','"+jk.getSelectedItem()+"','"+ttl.getText()+"','"+status.getSelectedItem()+"','"+pt.getSelectedItem()+"')";
PreparedStatement ps=connection.prepareStatement(sqlnya);
stat.executeUpdate(sqlnya);
JOptionPane.showMessageDialog(rootPane, "Succes");
}catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, "Connection failed "+e);
}
}
private void gantiActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
Class.forName("com.mysql.jdbc.Driver");
Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/uas", "root", "");
Statement stat=connection.createStatement();
String sqlnya="INSERT INTO karyawan VALUES ('"+id.getText()+"','"+nama.getText()+"','"+jabatan.getText()+"',"
+ "'"+alamat.getText()+"','"+jk.getSelectedItem()+"','"+ttl.getText()+"','"+status.getSelectedItem()+"','"+pt.getSelectedItem()+"')";
PreparedStatement ps=connection.prepareStatement(sqlnya);
stat.executeUpdate(sqlnya);
JOptionPane.showMessageDialog(rootPane, "Succes");
}catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, "Connection failed "+e);
}
}
private void deleteActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String x=JOptionPane.showInputDialog(null, "Please Enter the ID");
try {
Class.forName("com.mysql.jdbc.Driver");
Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/uas", "root", "");
Statement stat=connection.createStatement();
String del="DELETE FROM entry WHERE ID_Pegawai='"+x+"'";
stat.executeUpdate(del);
JOptionPane.showMessageDialog(rootPane, "Deleted");
id.setText("");
nama.setText("");
jabatan.setText("");
alamat.setText("");
jk.setSelectedItem("");
ttl.setText("");
status.setSelectedItem("");
pt.setSelectedItem("");
}catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, "Connection failed");
}
}
private void homeActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
new mu().setVisible(true);
this.dispose();
Berikut adalah hasil run nyaa :