Date conversion to oracle

1

I have a problem, I'm trying to save a date in oracle with the formatted dd/MM/yyyy , however, in the database it displays the date in dd/MM/yy format.

So, I came to doubt, if the type I used in the table is not appropriate, or if the date I move to the bank that is wrong.

In my DAO (in java), to include the date, I convert it with the following methods:

    public static java.sql.Date converteParaBanco(Date data) {
            return new java.sql.Date(data.getTime());
    }

   public static Date converteDoBanco(java.sql.Date data) {
            return new Date(data.getTime());
   }

Applying the method in DAO:

ps.setDate(5, ConverteData.converteParaBanco(pojoCompra.getDataCompra()));

Given a system.out in the above line, I realized that my method makes the date stay in 2017-09-22 format.

My attribute in the database is of type DATE .

What could I do to have the date saved and also returned in the form of dd/MM/yyyy ?

    
asked by anonymous 23.09.2017 / 02:10

1 answer

1

1st only in the user session change the format

sql> ALTER SESSION SET NLS_DATE_FORMAT = 'DD/MM/YYYY';
sql> select sysdate from dual;
SYSDATE

SQL> ALTER SESSION SET NLS_DATE_FORMAT = 'DD/MM/YY HH24:MI:SS';
--Sessão alterada.
SQL> select sysdate from dual;
SYSDATE

NLS_DATE_FORMAT = ‘DD/MM/YY HH24:MI:SS’ this is the oracle strings date format.

You can change the default if you are using SQLDeveloper

According to the following steps:

  • Tools > Preferences.
  •    
  • In the window that opens Select Database > NLS
  •    
  • No Date Format put the desired format

    
23.09.2017 / 02:30