Oracle Session date format for running Stored Data

Asked

Viewed 92 times

0

Talk guys, all good? I have a little problem that may be simple to solve, but I could not find solution so far.

I have procedures stored in the oracle database that need to be executed, however I am assembling these executions dynamically using Entitymanager. The problem itself is as follows, I have a precedent that needs a date parameter, but Procedure is using the DD-MM-YYYY format (this cannot be changed, as it is a legacy code that is still being used). I can format the date in the java layer and leave it in this format DD-MM-YYYY, but when I have the oracle Session run it is apparently converting to the format that is default in the DD-MON-RR database and when passing this date to the Procedure, there is an error that returns a message that displays the received date in the format '01/01/0020'.

Is there any way I could configure this form for the session while connecting to the Java layer? Or any way I can stop the oracle from converting the date? Below is an example of one of the execution attempts.

Edit: Using Alter Session solves, however you would need a way to do this in the java layer.

Print of part of the code

  • Have you tried an alter Session ? https://docs.oracle.com/cd/B19306_01/server.102/b14237/initparams122.htm#REFRN10119

  • Alter Session solves, but it is not feasible I change the session of all bases that are necessary, I wonder if there is a way to configure it in code

  • A login rigger maybe , I don’t know how to know if connect came from Java https://asktom.oracle.com/pls/asktom/asktom.search?tag=after-logon-trigger-200510 https://community.oracle.com/thread/5323?start=15&tstart=0

  • It may be an option, but it would be ideal something straight through java

  • I have a habit of always informing the data format in sql and plsql and never taking over from Session , but legacy mecher can be complicated , the idea of Rigger would be a stopgap , where we do not use Java so I did not have this experience. Did you see this ? https://community.oracle.com/thread/386043?start=0&tstart=0

  • I had not tested this alter Session execution with JDBC, I will try

  • I usually say, if you’re not programming Interprise’s warp factor, someone’s been through your same problem ... :)

  • kkkk makes sense

  • @Motta solved, with own jpa. Session Session = entityManager.unwrap(Session.class); Session.doWork(Connection -> { Preparedstatement preparedStatement; preparedStatement = Connection.prepareStatement("ALTER SESSION SET NLS_DATE_FORMAT = 'dd/MM/yyyy'"); preparedStatement.executeQuery(); preparedStatement.close(); });

Show 4 more comments

1 answer

0

Solution found, using entitymanger to change the session.

      Session session = entityManager.unwrap(Session.class);
                session.doWork(connection -> {
                    PreparedStatement preparedStatement;
                    preparedStatement = connection.prepareStatement("ALTER SESSION SET NLS_DATE_FORMAT = 'dd/MM/yyyy'");
                    preparedStatement.executeQuery();
                    preparedStatement.close();
                });
  • What I said here today on this site and I repeat, apart from you being programming the Interprise warp fusion, someone has already gone through your problem ...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.