Tabelspp Nova
Tabelspp Nova
Tabelspp Nova
Kelas : 3 PSI
package project_nova;
import java.sql.Connection;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
public frmspp() {
initComponents();
load_table();
kosong();
model.addColumn("tahun masuk");
model.addColumn("prodi");
model.addColumn("spp");
model.addColumn("bpp");
model.addColumn("npm");
try {
java.sql.Connection conn=(Connection)koneksiDB.configDB();
java.sql.Statement stm=conn.createStatement();
java.sql.ResultSet res=stm.executeQuery(sql);
while(res.next()) {
model.addRow(new Object[]{res.getString(1),res.getString(2),res.getString(3),res.getString(4),res.getString(5)});
datagridspp.setModel(model);
} catch (Exception e) {
cmbthnmasuk.setSelectedItem(this);
cmbprodi.setSelectedItem(this);
txtspp.setText(null);
txtbpp.setText(null);
txtnpm.setText(null);
@SuppressWarnings("unchecked")
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel2.setText("Tahun Masuk");
jLabel3.setText("prodi");
jLabel4.setText("SPP");
jLabel5.setText("BPP");
jLabel6.setText("NPM");
datagridspp.setModel(new javax.swing.table.DefaultTableModel(
},
new String [] {
));
datagridspp.addMouseListener(new java.awt.event.MouseAdapter() {
datagridsppMouseClicked(evt);
});
jScrollPane1.setViewportView(datagridspp);
btntambah.setText("Tambah");
btntambah.addActionListener(new java.awt.event.ActionListener() {
btntambahActionPerformed(evt);
});
btnhapus.setText("Hapus");
btnhapus.addActionListener(new java.awt.event.ActionListener() {
btnhapusActionPerformed(evt);
});
btnubah.setText("Ubah");
btnubah.addActionListener(new java.awt.event.ActionListener() {
btnubahActionPerformed(evt);
}
});
btncari.setText("Cari");
btncari.addActionListener(new java.awt.event.ActionListener() {
btncariActionPerformed(evt);
});
btnkeluar.setText("Keluar");
btnkeluar.addActionListener(new java.awt.event.ActionListener() {
btnkeluarActionPerformed(evt);
});
btnsimpan.setText("Simpan");
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel3)
.addComponent(jLabel4)
.addComponent(txtspp)
.addComponent(jLabel5)
.addComponent(txtbpp)
.addComponent(jLabel6)
.addComponent(txtnpm)
.addComponent(cmbthnmasuk, 0, 0, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnhapus)
.addComponent(btnsimpan))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(btntambah)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btncari))
.addGroup(layout.createSequentialGroup()
.addComponent(btnubah)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnkeluar)))))
.addContainerGap(10, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmbthnmasuk, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmbprodi, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(btntambah)
.addComponent(btncari)
.addComponent(btnsimpan))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnhapus)
.addComponent(btnkeluar)
.addComponent(btnubah))
.addContainerGap(30, Short.MAX_VALUE))
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>
try {
pst.setString(1, cari);
model.addColumn("thnmasuk");
model.addColumn("prodi");
model.addColumn("spp");
model.addColumn("bpp");
model.addColumn("npm");
while (res.next()) {
model.addRow(new Object[]{
res.getString("thnmasuk"),
res.getString("prodi"),
res.getString("spp"),
res.getString("bpp"),
res.getString("npm")
});
found = true;
datagridspp.setModel(model);
if (!found) {
res.close();
pst.close();
conn.close();
} catch (Exception e) {
} else {
try {
java.sql.Connection conn=(Connection)koneksiDB.configDB();
pst.execute();
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
load_table();
kosong();
//hapus data
try {
java.sql.Connection conn=(Connection)koneksiDB.configDB();
pst.execute();
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
load_table();
kosong();
// Edit Data
try {
java.sql.Connection conn=(Connection)koneksiDB.configDB();
java.sql.PreparedStatement pst=conn.prepareStatement(sql);
pst.execute();
} catch (Exception e) {
load_table();
kosong();
}
private void btnkeluarActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
cmbthnmasuk.setSelectedItem(thnmasuk);
cmbprodi.setSelectedItem(prodi);
txtspp.setText(spp);
txtbpp.setText(bpp);
txtnpm.setText(npm);
/**
*/
java.awt.EventQueue.invokeLater(new Runnable() {
new frmspp().setVisible(true);
}
});
}
Hasil :
1. Menampilkan Data