Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void nuevoUsuario(Usuario usuario) throws SQLException {
- try {
- con = DriverManager.getConnection("jdbc:mysql://localhost:3306/empresa", "root", "ticowrc2017");
- String sentencia = "INSERT INTO usuario (Cedula_Usuario,Nombre, Usuario, Contrasena, Rol) "
- + "VALUES (?,?,?,?,?)";
- ps = con.prepareStatement(sentencia);
- ps.setString(1, usuario.getCedulaUsuario());
- ps.setString(2, usuario.getNombre());
- ps.setString(3, usuario.getUsuario());
- ps.setString(4, usuario.getContrasena());
- ps.setInt(5, usuario.getRol());
- ps.executeUpdate();
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, "El usuario ya está registrado o uno de los campon"
- + "que ha llenado han sido ingresados en otro usuario");
- } finally {
- try {
- ps.close();
- con.close();
- } catch (SQLException ex) {
- Logger.getLogger(DATUsuario.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- public void nuevoUsuario() {
- int rolUs = 0;
- int digitosCedula = txtCedulaUser.getText().length();
- if (txtConf.getText().isEmpty() || txtNombre.getText().isEmpty()
- || txtPass.getText().isEmpty() || txtUsuario.getText().isEmpty()) {
- JOptionPane.showMessageDialog(null, "Todos los campos son obligatorios");
- } else if (digitosCedula != 10) {
- JOptionPane.showMessageDialog(null, "Número de cédula incorrecto");
- } else {
- String cedula = txtCedulaUser.getText();
- String nom = txtNombre.getText();
- String usu = txtUsuario.getText();
- String pass = txtPass.getText();
- String rol = (String) jComboBox1.getSelectedItem();
- if (rol.equals("Vendedor")) {
- rolUs = 0;
- }
- if (txtPass.getText().equals(txtConf.getText())) {
- String newPass = pass;
- pass = getMD5(newPass);
- objUs = new Usuario(cedula, nom, usu, pass, rolUs);
- try {
- usuario.nuevoUsuario(objUs);
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, "Error");
- }
- this.dispose();
- } else {
- JOptionPane.showMessageDialog(null, "Las contraseñas no coinciden");
- }
- }
- }
- private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {
- nuevoUsuarioVendedor();
- JOptionPane.showMessageDialog(
- null, "El usuario se creó correctamente, "
- + "a continuación deberá nvolver a ingresar "
- + "su usuario y contraseña");
- Validacion objV = new Validacion();
- objV.setVisible(true);
- this.dispose();
- }
Add Comment
Please, Sign In to add comment