try {
int res=0;
String a=jTextField1.getText();
String b=jPasswordField1.getText();
String c=jComboBox1.getSelectedItem().toString();
if (a.equals("")||
b.equals("")||
c.equals(""))
JOptionPane.showMessageDialog(null,"no se aceptan campos vacios");
else{
res=st.executeUpdate(" INSERT INTO usuarios VALUES(null,'"
+ a + "','"
+ b + "','"
+ c + "') ");
}
if (res==1)
JOptionPane.showMessageDialog(null,"Guardó Correctamente");
}
catch(SQLException c){
JOptionPane.showMessageDialog(null,"Error"+c.getMessage());
}
try{
conn=Enlace(conn);
st=conn.createStatement();
//Se hace la consulta SQL
rs=st.executeQuery("Select * from usuarios");
//Se llena el Combo con los registros
rs.next();
// el (2) representa la columna de la tabla
jTextField1.setText(rs.getString(1));
jPasswordField1.setText(rs.getString(2));
jComboBox1.setSelectedItem(rs.getString(3));
}
catch(SQLException c){
JOptionPane.showMessageDialog(null,"Error"+c.getMessage());
}
No hay comentarios:
Publicar un comentario