how to import excel data into 3 tables?

0

I happen to have 3 tables which are:

person: person_id (int), person (string), document (int).

animals: id (int), id_person, id_eps, pet (string), age (int).

eps: id_eps (int), name (string), cod_eps (int)

The fact is that the animal table is related to the person table and eps ... Now I must import an excel with the following data:

pet ---- age --------- person_name ---- document strong> -------- name_eps ---- code_eps

Pitbull ----------- 2 -------------- Antonio ------------ 1236 ------ ------------ confacab --------------- 1234

Chelsee -------- 3 ------------- Alberto ---------------- 1237 ------ ------------- confacab ---------------- 1235

Anita ------------ 3 ---------- Rosendo ---------------- 1238 ----- -------------- confacab ---------------- 12346

Firulay ---------- 3 ------------ Jorge Perez ------------ 1239 -------- ------------- confacab ------------------ 1246

The question is how do I import the excel to the bd in mysql and that in the table animals call me the primaries of the person and eps table (they are already related)?

is object-oriented programming and I'm working with netbeans

this would be the connection to the bd

//Conexion a base de datos Mysql
public void Conectar(){
    try{
        driver = "com.mysql.jdbc.Driver";
        Class.forName(driver);
        url = "jdbc:mysql://localhost:3306/cargamasiva";
        usuario = "root";
        contraseña = "";
        con = DriverManager.getConnection(url, usuario, contraseña); //Conexión MYSQL
        stm = con.createStatement(); //Crear statement
    }catch(SQLException e){ 
        System.out.println(e.getMessage());
    }catch(ClassNotFoundException e){
        System.out.println(e.getMessage());
    }
}

public void Desconectar (){
    try {
        stm.close();
        con.close();
    }catch (SQLException a) {
        System.out.println(a.getMessage());
    }
}

//Crear una tabla dinamica dependiendo la cadena de consulta SQL
public ResultSet ListarDatos(String consulta){
    try{
        Conectar();
        rs = stm.executeQuery(consulta);
        return rs;
    }catch(SQLException e){
        System.out.println(e.getMessage());
        return null;
    }
}

//Insertar, Actualizar y Eliminar datos de las tablas en la base de datos MYSQL
public boolean EditarDatos(String consulta){
    try{
        Conectar();
        System.out.print(consulta);
        stm.executeUpdate(consulta);
        return true;
    }catch(SQLException e){
        System.out.println(e.getMessage());
        return false;
    }
}

}

    
asked by Ferney Acevedo 24.05.2018 в 00:14
source

0 answers