Tema: Clase Date
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/10/2011, 08:03
lucho248
 
Fecha de Ingreso: octubre-2010
Mensajes: 154
Antigüedad: 13 años, 6 meses
Puntos: 5
Clase Date

Buenas y santas, tengo un problema con el manejo de la clase Date en java.
Resulta que la base de Datos tengo el campo Date. Y en mi programa en java (uso eclipse helios) tengo mis clases que tienen atributos Date().
bueno la recuperacion de los datos esta todo OK. Ahora cuando intento ingresar una nueva tupla en la tabla, me salta un error pero porque no puedo encontrar la forma de pasarle el formato de fecha de la base (yyyy-mm-dd) que maneja.

les paso un fragmento de codigo y la salida de la misma.

************************* CODIGO ************************
public boolean insertClientes(String nomCli, String apecli, String dni, int nro_doc, String direccion, int idLocalidad, int situacion, Date fechaNac, int telCarac, int tel, String sexo, String userOwner, Date fechaElimi,String tipoSexo)
{
System.out.println("dentro de ingreso de nuevo cliente");
String sql = "INSERT INTO `garantiasdb`.`clientes` (`NOMBRE`, `APELLIDO`, `TIPO_DOC`, " +
"`NRO_DOC`, `DIRECCION`, `IDLOCALIDA`, `SITUACION_`, `FECHA_NAC`, " +
"`TEL_CARAC`, `TELEFONO`, `SEXO`, `USEROWNER`, `FECHAELIMI`, `TIPO_SEXO`, `CODIGO`) VALUES ('"+nomCli+"', '"+apecli+"', '"+dni+"', '"+nro_doc+"', '"+direccion+"', '"+idLocalidad+"', '"+situacion+"', '"+fechaNac+"', " +
"'"+telCarac+"', '"+tel+"', '"+sexo+"', '"+userOwner+"', '"+fechaElimi+"', '"+tipoSexo+"', NULL);";
System.out.println("dentro de procesos, antes del TRY-CATCH del ingreso de nuevo cliente");
System.out.println(sql);
try {
System.out.println("dentro de procesos, apenas entrado al TRY-CATCH");
PreparedStatement st = Conexion.ObtenerConexion().prepareStatement(sql);
/*
* actualiza el cliente con dni numero "nro_doc"
* */
ResultSet rs = st.executeQuery();
} catch (SQLException e) {
System.out.print("ERROR EN LA ACTUALIZACION DE DATOS DE LA BASE EN LA INSERCION DE CLIENTE");
e.printStackTrace();
return false;
}
return true;
}


public static void main(String[] args) throws ParseException {
Procesos proc = new Procesos();
System.out.println("dentro del MAIN principal de la clase PROCESOS");
System.out.print("ACTUALIZACION DE CLIENTES \n\n");
int doc = 33444555;
String nombre, apellido, tipDoc, Dir, sexo, userO, tipoSexo,fnac, feli;
int idLoc, sit, telCarac, telef, cod;
Date fechaNac, fechaEli;
nombre = "nomCli2";
apellido = "apecli";
tipDoc = "dni2";
Dir = "calle2 4321";
sexo = "F";
userO = "0";
tipoSexo = "0";
idLoc = 4993;
sit = 3;
telCarac = 3483;
telef = 444999;

fnac = new String ("2011-7-15");
feli = new String ("2020-7-25");

SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");

fechaNac = sdf1.parse(fnac);
System.out.println("fechaNac parse: "+sdf1.parse(fnac));
System.out.println("fechaNac format: "+sdf1.format(fechaNac));
fechaEli = sdf1.parse(feli);
System.out.println("fechaEli: "+sdf1.format(fechaEli));

proc.insertClientes(nombre, apellido, tipDoc, doc, Dir, idLoc, sit, fechaNac, telCarac, telef, sexo, userO, fechaEli, tipoSexo);
System.out.println("inserto un nuevo cliente con DNI: "+doc);
}

************************* SALIDA ************************

dentro del MAIN principal de la clase PROCESOS


ACTUALIZACION DE CLIENTES

fechaNac parse: Fri Jul 15 00:00:00 GMT-03:00 2011
fechaNac format: 2011-07-15
fechaEli: 2020-07-25
dentro de ingreso de nuevo cliente
dentro de procesos, antes del TRY-CATCH del ingreso de nuevo cliente
INSERT INTO `garantiasdb`.`clientes` (`NOMBRE`, `APELLIDO`, `TIPO_DOC`, `NRO_DOC`, `DIRECCION`, `IDLOCALIDA`, `SITUACION_`, `FECHA_NAC`, `TEL_CARAC`, `TELEFONO`, `SEXO`, `USEROWNER`, `FECHAELIMI`, `TIPO_SEXO`, `CODIGO`) VALUES ('nomCli2', 'apecli', 'dni2', '33444555', 'calle2 4321', '4993', '3', 'Fri Jul 15 00:00:00 GMT-03:00 2011', '3483', '444999', 'F', '0', 'Sat Jul 25 00:00:00 GMT-03:00 2020', '0', NULL);
dentro de procesos, apenas entrado al TRY-CATCH
Conexion Exitosa1
Conexion Exitosa2
ERROR EN LA ACTUALIZACION DE DATOS DE LA BASE EN LA INSERCION DE CLIENTEjava.sql.SQLException: Can not issue data manipulation statements with executeQuery().
at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:1073)
at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:982)
at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:927)
at com.mysql.jdbc.StatementImpl.checkForDml(Statement Impl.java:468)
at com.mysql.jdbc.PreparedStatement.executeQuery(Prep aredStatement.java:2182)
at Implement.Procesos.insertClientes(Procesos.java:82 2)
at Implement.Procesos.main(Procesos.java:1074)

inserto un nuevo cliente con DNI: 33444555



************************* FIN CODIGO ************************

Lo que necesito es pasarle a la base la fecha con el formato yyyy-mm-dd, estimo que el error es la fecha, por la salida por consola que es nada que ver al formato que necesito pasarle...
cualquier ayuda sera bien venida y agradecida.
Abrazo.
Luciano.