Source Code Button Simpan Edit dan Delete

Source Code Button Simpan Edit dan Delete

Nah sekarang gua mau bagi-bagi codingan bro mumpung gua masih baik langsung ajh ntar keburu ilang kan kamvret ! Langsung ajh Copy Paste dibawah sini .

private void buttonSimpanActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
        try{
            String sql = "INSERT INTO datapelanggan values('"+textId.getText()+"','"+textNama.getText()+"','"+textALamat.getText()+"','"+comboJenkel.getSelectedItem()+"')";
            java.sql.Connection conn =Config.configDB();
            java.sql.PreparedStatement pst = conn.prepareStatement(sql);
            pst.execute();
            JOptionPane.showMessageDialog(null, "Data berhasil di simpan");
        }catch(Exception e){
            JOptionPane.showMessageDialog(this, e.getMessage());
        }
        load_tabel();
    }                                                                                   

    private void butKembaliActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        this.hide();
        Form wer = new Form();
        wer.setVisible(true);
    }                                         

    private void tableDataMouseClicked(java.awt.event.MouseEvent evt) {                                      
        // TODO add your handling code here:
        int baris = tableData.rowAtPoint(evt.getPoint());
        String id = tableData.getValueAt(baris, 0).toString();
        textId.setText(id);
        String nama = tableData.getValueAt(baris, 1).toString();
        textNama.setText(nama);
        String alamat = tableData.getValueAt(baris, 2).toString();
        textALamat.setText(alamat);
        String jenis = tableData.getValueAt(baris, 3).toString();
        comboJenkel.setSelectedItem(jenis);
    }                                     

    private void btnHapusActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        try{
            String sql="DELETE FROM `datapelanggan` WHERE `datapelanggan`.`id` ='"+textId.getText()+"'";
            java.sql.Connection conn =Config.configDB();
            java.sql.PreparedStatement pst = conn.prepareStatement(sql);
            pst.execute();
                JOptionPane.showMessageDialog(null,"Data berhasil dihapus !!!");
        }catch(Exception e){
                JOptionPane.showMessageDialog(null,"Data gagal dihapus!!!");
        }
        load_tabel();
    } 

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel