简体   繁体   中英

ORMLite and setting session date variables

What is the correct way of running a session formatting query via ORMLite? The reason that I am setting session formatting is that the queries that I run never retrieve any results and I keep getting an absurd error (you can see it below).

This is what I am currently doing to set up the session format:

String sqlSession = "alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS';";
Conn.My_Dao().queryRaw(sqlSession);

But I keep getting the following error:

java.sql.SQLException: Could not perform raw query for
    alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS';

The reason I am doing that (as I mentioned earlier) - is that for any query that I run I get the following error:

java.sql.SQLException: Problems parsing default date string '2021-01-01 00:00:00'
    using 'yyyy-MM-dd HH:mm:ss.SSSSSS'

I had experienced something similar with Oracle SQL in the past (with an old PHP project to be precise) and I just handled it by setting the session formating to the aforementioned one.

However, I agree that this might not be the most elegant solution to this problem. What would the best way to handle it?

java.sql.SQLException: Could not perform raw query for alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS';

In the future, make sure to post more of the exception when you get one. I suspect that there was a "Caused by" line later on in the exception that said something about this not being a query .

I'm guessing that you should use the Dao.executeRaw(...) method instead of Dao.queryRaw(...) . Queries really need to be select statements which return results.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM