You are on page 1of 2

MANTENIMIENTO NETBEANS VS SQL

public class FrmAcceso extends javax.swing.JFrame {


ConexBD conector;
public FrmAcceso() {
initComponents();
conector=new ConexBD("UsuariosBD");
this.getContentPane().setBackground(new Color(100,90,10));
}

void listado(){
String sql="select * from tbl_Usuarios";
try {
ResultSet rs=conector.getSt().executeQuery(sql);
DefaultTableModel m1=(DefaultTableModel)tabla1.getModel();
m1.setRowCount(0);
while (rs.next()) {
Object []fila={rs.getString(1),rs.getString(2),rs.getString(3)};
m1.addRow(fila);
}
} catch (Exception e) {
}
}
private void btnListadoActionPerformed(java.awt.event.ActionEvent evt) {
listado();
}
private void btnAgregarActionPerformed(java.awt.event.ActionEvent evt) {
String usu,clave,nivel,sql;
usu=txtuser.getText();
clave=txtpassword.getText();
nivel=txtnivel.getText();
sql="insert into tbl_usuarios values('"+usu+"','"+clave+"','"+nivel+"') ";
try {
conector.getSt().executeUpdate(sql);
listado();
} catch (Exception e) {
}
}

private void btneliminarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String usuarioElim=JOptionPane.showInputDialog(null, "Ingresa nombre del usuario a eliminar...?");
String sql="delete from tbl_usuarios where [user]='"+usuarioElim+"'";
try {
int rs=conector.getSt().executeUpdate(sql);
listado();
} catch (Exception e) {
}
}

private void btnConsultarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String userbus=JOptionPane.showInputDialog(null, "Ingresa nombre del usuario a Buscar...?");
String sql="select * from tbl_usuarios where [user]='"+userbus+"'";
try {
ResultSet rs=conector.getSt().executeQuery(sql);
if (rs.next()) {
Object []fila={rs.getString(1),rs.getString(2),rs.getString(3)};
txtuser.setText(""+fila[0]);
txtpassword.setText(""+fila[1]);
txtnivel.setText(""+fila[2]);
} else {
JOptionPane.showMessageDialog(null, "Usuario " +userbus+ " No existe en esta BD");
}
} catch (Exception e) {
}
}

private void btnmodificarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String usu,clave,nivel,sql;
usu=txtuser.getText();
clave=txtpassword.getText();
nivel=txtnivel.getText();
sql="Update tbl_usuarios set [user]='"+usu+"',password='"+clave+"',nivel='"+nivel+"' where [user]='"+usu+"'";
try {
conector.getSt().executeUpdate(sql);
listado();
} catch (Exception e) {
}

}

You might also like