private void btnubahActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnubahActionPerformed try { Class.forName("com.mysql.jdbc.Driver"); // MENYIAPKAN KONEKSI DAN PARAMETERNYA String urldb = "jdbc:mysql://localhost:3306/hotel"; String user = "******"; String password = ""; Connection koneksi = DriverManager.getConnection(urldb, user, password); // Query SQL dan Eksekuusinya Statement st = koneksi.createStatement(); String jnsKelamin; if (rbtnlaki.isSelected()) { jnsKelamin = "laki-laki"; } else { jnsKelamin = "perempuan"; } String strSQL = "update master_costumer set id_ktp='" + txtid.getText() + "',nama='" + txtnama.getText() + "', alamat='" + txtalamat.getText() + "', jenis_kelamin='" + jnsKelamin + "' where id_ktp='" + txtid.getText() + "'"; st.executeUpdate(strSQL); data[0] = txtid.getText(); data[1] = txtnama.getText(); data[2] = txtalamat.getText(); data[3] = jnsKelamin; tblModel.removeRow(row); tblModel.insertRow(row, data); txtid.setText(""); txtnama.setText(""); txtalamat.setText(""); st.close(); koneksi.close(); } catch (ClassNotFoundException cnfe) { System.out.println("KESALAHAN SAAT" + "ME-LOAD DRIVER JDBC \n" + cnfe.getMessage()); } catch (SQLException sqle) { System.out.println( "KESALAHAN SAAT KONEKSI ATAU " + "KESALAHAN QUERY SQL \n" + sqle.getMessage()); } } // GEN-LAST:event_btnubahActionPerformed
public void Tampil() { row = tblmaster.getSelectedRow(); txtid.setText(tblModel.getValueAt(row, 0).toString()); txtnama.setText(tblModel.getValueAt(row, 1).toString()); txtalamat.setText(tblModel.getValueAt(row, 2).toString()); if (tblModel.getValueAt(row, 3).toString().equals("Laki-laki")) { rbtnlaki.setSelected(true); } else { rbtnperempuan.setSelected(true); } }
private void jButton3ActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton3ActionPerformed // TODO add your handling code here: try { Class.forName("com.mysql.jdbc.Driver"); // MENYIAPKAN KONEKSI DAN PARAMETERNYA String urldb = "jdbc:mysql://localhost:3306/hotel"; String user = "******"; String password = ""; Connection koneksi = DriverManager.getConnection(urldb, user, password); // Query SQL dan Eksekuusinya Statement st = koneksi.createStatement(); String strSQL = "delete from master_costumer where id_ktp='" + txtid.getText() + "'"; st.executeUpdate(strSQL); tblModel.removeRow(row); txtid.setText(""); txtnama.setText(""); txtalamat.setText(""); st.close(); koneksi.close(); } catch (ClassNotFoundException cnfe) { System.out.println("KESALAHAN SAAT" + "ME-LOAD DRIVER JDBC \n" + cnfe.getMessage()); } catch (SQLException sqle) { System.out.println( "KESALAHAN SAAT KONEKSI ATAU " + "KESALAHAN QUERY SQL \n" + sqle.getMessage()); } } // GEN-LAST:event_jButton3ActionPerformed