FUNCTION INSERTAR
Cita:
FUNCTION LISTAR public boolean InsertEmployee(EntityEmployee entityemployee) {
Connection cn = null;
CallableStatement cl = null;
boolean opeEstado = false;
try {
String call = "{CALL InsertEmployee(?,?,?,?,?,?,?,?,?,?)}";
cn = Conexion.getConexion();
cn.setAutoCommit(false);
cl = cn.prepareCall(call);
cl.setString(1, entityemployee.getFirstName());
cl.setString(2, entityemployee.getLastName());
cl.setString(3, entityemployee.getDni());
cl.setDate(4, new java.sql.Date(entityemployee.getDateNac().getTime( )));
cl.setString(5, entityemployee.getAdress());
cl.setString(6, entityemployee.getPhone());
cl.setString(7, entityemployee.getCellphone());
cl.setInt(8, entityemployee.getJobID());
cl.setDate(9, new java.sql.Date(entityemployee.getDateIni().getTime( )));
cl.setString(10, entityemployee.getEmail());
if (cl.executeUpdate() == 1) {
opeEstado = true;
} else {
opeEstado = false;
}
if (opeEstado) {
cn.commit();
} else {
Conexion.deshacerCambios(cn);
}
Conexion.cerrarCall(cl);
Conexion.cerrarConexion(cn);
return opeEstado;
} catch (SQLException e) {
e.printStackTrace();
Conexion.deshacerCambios(cn);
Conexion.cerrarCall(cl);
Conexion.cerrarConexion(cn);
} catch (Exception e) {
e.printStackTrace();
Conexion.deshacerCambios(cn);
Conexion.cerrarCall(cl);
Conexion.cerrarConexion(cn);
}
return opeEstado;
}
Connection cn = null;
CallableStatement cl = null;
boolean opeEstado = false;
try {
String call = "{CALL InsertEmployee(?,?,?,?,?,?,?,?,?,?)}";
cn = Conexion.getConexion();
cn.setAutoCommit(false);
cl = cn.prepareCall(call);
cl.setString(1, entityemployee.getFirstName());
cl.setString(2, entityemployee.getLastName());
cl.setString(3, entityemployee.getDni());
cl.setDate(4, new java.sql.Date(entityemployee.getDateNac().getTime( )));
cl.setString(5, entityemployee.getAdress());
cl.setString(6, entityemployee.getPhone());
cl.setString(7, entityemployee.getCellphone());
cl.setInt(8, entityemployee.getJobID());
cl.setDate(9, new java.sql.Date(entityemployee.getDateIni().getTime( )));
cl.setString(10, entityemployee.getEmail());
if (cl.executeUpdate() == 1) {
opeEstado = true;
} else {
opeEstado = false;
}
if (opeEstado) {
cn.commit();
} else {
Conexion.deshacerCambios(cn);
}
Conexion.cerrarCall(cl);
Conexion.cerrarConexion(cn);
return opeEstado;
} catch (SQLException e) {
e.printStackTrace();
Conexion.deshacerCambios(cn);
Conexion.cerrarCall(cl);
Conexion.cerrarConexion(cn);
} catch (Exception e) {
e.printStackTrace();
Conexion.deshacerCambios(cn);
Conexion.cerrarCall(cl);
Conexion.cerrarConexion(cn);
}
return opeEstado;
}
Cita:
PD: public ArrayList<EntityEmployee> ListEmployee() {
Connection cn = null;
PreparedStatement ps = null;
ResultSet rs = null;
ArrayList<EntityEmployee> lstEmployees = new ArrayList<EntityEmployee>();
try {
String prepStm = "Select e.EmployeeID,e.FirstName,e.LastName,e.DNI,e.DateNa c,e.Adress,e.Phone,e.CellPhone,e.JobID,J.JobName,e .FechaInicio,e.Email from Employees e, Job j Where e.Estate='A' And j.JobID=e.JobID";
cn = Conexion.getConexion();
ps = cn.prepareStatement(prepStm);
rs = ps.executeQuery();
while (rs.next()) {
EntityEmployee objEmployee = new EntityEmployee();
objEmployee.setEmployee(rs.getString(1));
objEmployee.setFirstName(rs.getString(2));
objEmployee.setLastName(rs.getString(3));
objEmployee.setDni(rs.getString(4));
objEmployee.setDateNac(rs.getDate(5));
objEmployee.setAdress(rs.getString(6));
objEmployee.setPhone(rs.getString(7));
objEmployee.setCellphone(rs.getString(8));
objEmployee.setJobID(rs.getInt(9));
objEmployee.setJobName(rs.getString(10));
objEmployee.setDateIni(rs.getDate(11));
objEmployee.setEmail(rs.getString(12));
//agregamos a la lista el objeto client
lstEmployees.add(objEmployee);
}
Conexion.cerrarPrep(ps);
Conexion.cerrarConexion(cn);
return lstEmployees;
} catch (SQLException e) {
e.printStackTrace();
Conexion.deshacerCambios(cn);
Conexion.cerrarPrep(ps);
Conexion.cerrarConexion(cn);
} catch (Exception e) {
e.printStackTrace();
Conexion.deshacerCambios(cn);
Conexion.cerrarPrep(ps);
Conexion.cerrarConexion(cn);
}
return null;
}
Connection cn = null;
PreparedStatement ps = null;
ResultSet rs = null;
ArrayList<EntityEmployee> lstEmployees = new ArrayList<EntityEmployee>();
try {
String prepStm = "Select e.EmployeeID,e.FirstName,e.LastName,e.DNI,e.DateNa c,e.Adress,e.Phone,e.CellPhone,e.JobID,J.JobName,e .FechaInicio,e.Email from Employees e, Job j Where e.Estate='A' And j.JobID=e.JobID";
cn = Conexion.getConexion();
ps = cn.prepareStatement(prepStm);
rs = ps.executeQuery();
while (rs.next()) {
EntityEmployee objEmployee = new EntityEmployee();
objEmployee.setEmployee(rs.getString(1));
objEmployee.setFirstName(rs.getString(2));
objEmployee.setLastName(rs.getString(3));
objEmployee.setDni(rs.getString(4));
objEmployee.setDateNac(rs.getDate(5));
objEmployee.setAdress(rs.getString(6));
objEmployee.setPhone(rs.getString(7));
objEmployee.setCellphone(rs.getString(8));
objEmployee.setJobID(rs.getInt(9));
objEmployee.setJobName(rs.getString(10));
objEmployee.setDateIni(rs.getDate(11));
objEmployee.setEmail(rs.getString(12));
//agregamos a la lista el objeto client
lstEmployees.add(objEmployee);
}
Conexion.cerrarPrep(ps);
Conexion.cerrarConexion(cn);
return lstEmployees;
} catch (SQLException e) {
e.printStackTrace();
Conexion.deshacerCambios(cn);
Conexion.cerrarPrep(ps);
Conexion.cerrarConexion(cn);
} catch (Exception e) {
e.printStackTrace();
Conexion.deshacerCambios(cn);
Conexion.cerrarPrep(ps);
Conexion.cerrarConexion(cn);
}
return null;
}
-El campo de en la BD es DATE.
-Campo de erroes DateNac y DateIni