Problem with date format

1

I am working on a mobile application in which I keep data in my device database, one of those fields is the date and time but when I want to insert these fields from my application to Oracle, it marks me an error the format of the date which I have it in the following way

    public static String fecha(){
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    String currentDateandTime = sdf.format(new Date());
    return currentDateandTime;
    }

This method I use to insert my data

And with this line is what I call my method

String fechaR = manejoDeDatos.fecha();
manejoDeDatos.registrarResultados(mContext, String.valueOf(intentIdUsuario), resultadoQR, fechaR);

To test if my web service inserts, I'm using postman and that's where the error marks me

In my stored procedure I have

    create or replace PROCEDURE SP_AR_INSERT_JSON_APP(
  ID_USUARIO IN NUMBER,
  INFORMACION_QR IN NVARCHAR2,
  FECHA IN DATE,
  ID_NUEVO OUT NUMBER )
AS
BEGIN
  INSERT INTO XXVIA_LM_TB_ANES_RESULTADOS
      (NUMB_ID_RESULTADOS, 
       DATE_FECHA_HORA_INICIO, 
       NUMB_ID_USUARIO, 
       VCHA_INFORMACIONQR)
    VALUES 
    (((SELECT NVL(MAX(NUMB_ID_RESULTADOS), 0) FROM XXVIA_LM_TB_ANES_RESULTADOS) + 1),
       FECHA, 
       ID_USUARIO,
       INFORMACION_QR)
       RETURNING NUMB_ID_RESULTADOS INTO ID_NUEVO;
       COMMIT;

END SP_AR_INSERT_JSON_APP;

If you need any other information, I'll gladly share it with you. By pure chance, someone knows how to solve this error, if you could guide me, I would appreciate it very much.

    
asked by Amairani Fernanda 20.03.2018 в 21:59
source

1 answer

1

The error is:

ORA-01861: El literal no coincide con la cadena de formato.
ORA-01861: literal does not match format string.

occurs in your Stored Procedure when trying to insert the "date" in a format that is incorrect, the format you use to send as a date to your Web Service method is:

"yyyy/MM/dd HH:mm:ss"

therefore modify your Stored Procedure to convert the value of FECHA to date using the method TO_DATE ()

TO_DATE(FECHA, 'YYYY/MM/DD HH:MI:SS')

This would be the change in the SP:

   create or replace PROCEDURE SP_AR_INSERT_JSON_APP(
  ID_USUARIO IN NUMBER,
  INFORMACION_QR IN NVARCHAR2,
  FECHA IN DATE,
  ID_NUEVO OUT NUMBER )
AS
BEGIN
  INSERT INTO XXVIA_LM_TB_ANES_RESULTADOS
      (NUMB_ID_RESULTADOS, 
       DATE_FECHA_HORA_INICIO, 
       NUMB_ID_USUARIO, 
       VCHA_INFORMACIONQR)
    VALUES 
    (((SELECT NVL(MAX(NUMB_ID_RESULTADOS), 0) FROM XXVIA_LM_TB_ANES_RESULTADOS) + 1),
       TO_DATE(FECHA, 'YYYY/MM/DD HH:MI:SS'), 
       ID_USUARIO,
       INFORMACION_QR)
       RETURNING NUMB_ID_RESULTADOS INTO ID_NUEVO;
       COMMIT;

END SP_AR_INSERT_JSON_APP;
    
answered by 21.03.2018 / 00:41
source