0

I'm trying to insert a date into a db oracle column using offsetdatetime, but I'm having some problem. With The last solution I've tried, I would able to write the date in the db, but the date is not correct "08-JAN-70 04:05:02".

private static final String INSERT_QUERY = "INSERT INTO TABLENAME (N_ID_INVOICE, "
                                                                        + "N_ID_NOTS_SDI, "
                                                                        + "N_TYPE_NOTS,"
                                                                        + "N_DATE_NOTS, "
                                                                        + "N_STATE_NOTS, "
                                                                        + "N_DES_NOTS, "
                                                                        + "N_XML_NOTS)"
                                             + " values "
                                             + "(?,?,?,?,?,?,convert(?,'WE8MSWIN1252','UTF8'))";

    @Override
    public synchronized void insertNotis(Connection conn,String invoiceUID, String invoiceNotifUID, OffsetDateTime utcDate, String notificationType,
            String note, String typeNots,Clob notifSdiClob) throws SQLException 
    {

           Timestamp t=new Timestamp(utcDate.getNano());


        PreparedStatement pstmt=null;

        pstmt=conn.prepareStatement(INSERT_QUERY);
        pstmt.setString(1, invoiceUID);
        pstmt.setString(2, invoiceNotifUID);
        pstmt.setString(3, typeNots);
        pstmt.setTimestamp(4, t);
        pstmt.setString(5, notificationType);
        pstmt.setString(6, note);
        pstmt.setClob(7, notifSdiClob);


        pstmt.execute();


    }

Convert OffsetDateTime to UTC Timestamp I saw this solution, but I can't follow it because, for this project, I must only use org.threeten.bp.OffsetDateTime.

Scripta14
  • 463
  • 2
  • 8
  • 22

1 Answers1

0

I found out many way to manage the date, but not always the solution worked well. I read better the org.threeten.bp's javadoc and the solution was in front of me. I think this solution is the better that I've found out...I Hope that it will be useful to others.

String dateTime=utcDate.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
                       .replaceAll("T", " ");
Timestamp t=Timestamp.valueOf(dateTime);
Scripta14
  • 463
  • 2
  • 8
  • 22