- Share this text:
Untitled - posted by guest on 30th August 2020 05:03:03 AM
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package marketpro2020;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
/**
*
* @author rpalm
*/
public class Metodos {
/**
************************************************
************************************************
*************METODO DE CONEXION****************
************************************************
************************************************
*/
public Statement conectar(){
java.sql.Statement st=null;
boolean estado = false;
try{
Class.forName("com.mysql.jdbc.Driver");
Connection cn;
cn = DriverManager.getConnection("jdbc:mysql://localhost:3306/marketpro", "root", "");
JOptionPane.showMessageDialog(null, "Conexion a BD exitosa");
st=cn.createStatement();
estado = true;
} catch (NullPointerException e) {
estado=false;
System.out.println(""+e);
} catch (ClassNotFoundException ex) {
estado=false;
System.out.println(""+ex);
} catch (SQLException ex) {
estado=false;
JOptionPane.showMessageDialog(null, "Problemas de conexion");
System.out.println(""+ex);
}
return (Statement) st;
/**
************************************************
************************************************
*************AGREGAR USUARIOS****************
************************************************
************************************************
*/
public void insertarUsuario (Usuarios usuario)
{
try
{
ConnectionManager cn = new ConnectionManager();
Connection connection = cn.getConnection();
Statement st=connection.createStatement();
st.executeUpdate("INSERT INTO empleado (Rut_Empleado, Nombre, Apellido, password, permiso) "
+ "VALUE ('"+usuario.getRut()+"','"+usuario.getNombre()+"',"+usuario.getApellido()+","+usuario.getPassword()+","+usuario.getPermiso()+")");
JOptionPane.showMessageDialog(null, "Usuario "+usuario.getNombre()+" ha sido ingresado exitosamente");
connection.close();
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, "No se pudo ingresar el nuevo usuario. \nConsulte a su programador.");
System.out.println(e);
}
}
/**
************************************************
************************************************
*************AGREGAR USUARIOS****************
************************************************
************************************************
*/
}