You are on page 1of 2

private void btnnuevoActionPerformed(java.awt.event.

ActionEvent evt) { NUEVO

txtco.setText("");
txtno.setText("");
txtap.setText("");
txtam.setText("");
txtdi.setText("");
txtco.requestFocus();
}

private void btngrabarActionPerformed(java.awt.event.ActionEvent evt)


{ AGREGAR
int rpta;
String sql;
rpta = JOptionPane.showConfirmDialog(rootPane, "Deseas Grabar", "Grabar",
JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
conectar();
if (rpta == 0) {
try {
llenar();
sql = "insert into cliente values('" + co + "','" + no + "','" + ap
+ "','" + am + "','" + di + "')";
stmt = con.createStatement();
stmt.execute(sql);
con.close();
stmt.close();
limpiartabla();
mostrar();
} catch (Exception ex) {
JOptionPane.showMessageDialog(rootPane, ex.getMessage());
}
}

private void btnmodificarActionPerformed(java.awt.event.ActionEvent evt)


{ MODIFICAR
int rpta;
String sql;
rpta = JOptionPane.showConfirmDialog(rootPane, "Deseas Modificar",
"Modificar", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
conectar();
if (rpta == 0) {
try {
llenar();
sql = "update cliente set
nom_cli='"+no+"',ape_pat_cli='"+ap+"',ape_mat_cli='"+am+"', dir_cli='"+di+"' where
cod_cli='"+co+"'";
stmt = con.createStatement();
stmt.execute(sql);
con.close();
stmt.close();
limpiartabla();
mostrar();
} catch (SQLException ex) {
JOptionPane.showMessageDialog(rootPane, ex.getMessage());
}
}
private void btneliminarActionPerformed(java.awt.event.ActionEvent evt)
{ ELIMINAR
int rpta;
String sql;
rpta = JOptionPane.showConfirmDialog(rootPane, "Deseas Eliminar",
"Eliminar", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
conectar();
if (rpta == 0) {
try {
llenar();
sql = "delete from cliente where cod_cli='"+co+"'";
stmt = con.createStatement();
stmt.execute(sql);
con.close();
stmt.close();
limpiartabla();
mostrar();
} catch (Exception ex) {
JOptionPane.showMessageDialog(rootPane, ex.getMessage());
}
} // TODO add your handling code here:
}

int x= (tbldatos.getSelectedRow()); TABLA


txtco.setText(String.valueOf(tbldatos.getValueAt(x, 0)));
txtno.setText(String.valueOf(tbldatos.getValueAt(x, 1)));
txtap.setText(String.valueOf(tbldatos.getValueAt(x, 2)));
txtam.setText(String.valueOf(tbldatos.getValueAt(x, 3)));
txtdi.setText(String.valueOf(tbldatos.getValueAt(x, 4)));
}

You might also like