Salam Programer
Selamat datang di blog saya sipenakluk computer
Buat procedure gaji
private void gaji(){
DefaultTableModel model = new DefaultTableModel();
//Ingat variable name untuk table yaaa.....beb...
//tblpeg ini adalah nama jtable
tblpeg1.setModel(model);
model.addColumn("No Slip");
model.addColumn("NIP");
model.addColumn("Tanggal");
model.addColumn("Pendapatan");
model.addColumn("Potongan");
model.addColumn("Gaji Bersih");
model.getDataVector().removeAllElements();
model.fireTableDataChanged();
try {
// Proses panggil koneksi
Connection cn = koneksi.getKoneksi();
Statement st = cn.createStatement();
// Proses Query tampil data
String sql = "SELECT * FROM gaji";
ResultSet rst = st.executeQuery(sql);
// Menampilkan Hasil ke masing2 kolom tabel
while (rst.next()) {
Object [] ob = new Object[6];
ob[0]=rst.getInt("No_Slip");
ob[1]=rst.getString("NIP");
ob[2]=rst.getString("Tanggal");
ob[3]=rst.getString("Pendapatan");
ob[4]=rst.getString("Potongan");
ob[5]=rst.getString("Gaji_Bersih");
model.addRow(ob);
}
rst.close();
st.close();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null,"Gagal"+e);
}
}
private void pegawai(){
DefaultTableModel model = new DefaultTableModel();
tblpeg.setModel(model);
model.addColumn("NIP");
model.addColumn("Nama Pegawai");
model.addColumn("Alamat");
model.addColumn("Jenis Kelamin");
model.addColumn("Tanggal Lahir");
model.addColumn("Kode Jabatan");
model.addColumn("Golongan");
model.addColumn("Status");
model.getDataVector().removeAllElements();
model.fireTableDataChanged();
try {
// Proses panggil koneksi
Connection cn = koneksi.getKoneksi();
Statement st = cn.createStatement();
// Proses Query tampil data
String sql = "SELECT * FROM pegawai";
ResultSet rst = st.executeQuery(sql);
// Menampilkan Hasil ke masing2 kolom tabel
while (rst.next()) {
Object [] ob = new Object[8];
ob[0]=rst.getInt("NIP");
ob[1]=rst.getString("Nama_Pegawai");
ob[2]=rst.getString("Alamat");
ob[3]=rst.getString("Jenis_Kelamin");
ob[4]=rst.getString("Tanggal_Lahir");
ob[5]=rst.getString("Kode_Jabatan");
ob[6]=rst.getString("Golongan");
ob[7]=rst.getString("Status");
model.addRow(ob);
}
rst.close();
st.close();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null,"Gagal"+e);
}
Procedure Simpan
try{
String A = txtnip1.getText();
String C = txtpdt2.getText();
String D=txtptg.getText();
SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd",Locale.getDefault());
String dt = date.format(tgdate1.getDate());
String E = txtgj.getText();
Connection cn = koneksi.getKoneksi();
Statement sd = cn.createStatement();
String sql = "INSERT INTO gaji VALUES(null,'"+A+"','"+dt+"','"+C+"','"+D+"','"+E+"' ) ";
PreparedStatement pst = cn.prepareStatement(sql);
pst.execute();
JOptionPane.showMessageDialog(null, "Data Gaji Berhasil Disimpan");
tblgaji();
bersih();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, e);
}}
Selamat Mencoba semoga berhasil
No comments:
Post a Comment