Since the elimination of the JDBC bridge from Java 1.8 (which we still mourn) and the move to UcanAccess, I've been debugging SQL code that in the past never gave me any issues.. One of the statements are:
DELETE TreatmentRecords.DateGiven, TreatmentRecords.TimeGiven, SInformation.Surname, SInformation.FirstNames, TreatmentRecords.Diagnosis, TreatmentRecords.*
FROM SInformation INNER JOIN TreatmentRecords ON SInformation.SID = TreatmentRecords.SID
WHERE (((TreatmentRecords.DateGiven)=#2015-03-07#) AND ((TreatmentRecords.TimeGiven)='17;16') AND ((SInformation.Surname)='Doe') AND ((SInformation.FirstNames)='John') AND ((TreatmentRecords.Diagnosis)='Headache'));
When executing in Access itself, I get absolutely no errors or problems.
However Ucancess throws the following exception:
net.ucanaccess.jdbc.UcanaccessSQLException: unexpected token: TREATMENTRECORDS required: FROM
Any ideas on why would be highly appreciated!
It's a non standard SQL delete statement which is not supported by ucanaccess, even if the Jet engine does. Nothing strange about it.
So you have to use the standard SQL for this.
EDIT
e.g., something like this(I haven't added all the conditions):
DELETE FROM TreatmentRecords tr WHERE
tr.DateGiven=#2015-03-07# AND EXISTS
(SELECT * FROM SInformation s WHERE s.SID=tr.SID AND s.Surname='Doe')
Related
I recently updated a project's jooq version from 3.13.5 to 3.14.15. I've rerun jooq-codegen. I'm using MySQL 5.7.
When running one of my tests - it performs a DAOImpl.exists. That call generates the following exception:
org.jooq.exception.DataAccessException: SQL [select `count`(*) from `users` where `users`.`id` = ?]; You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*) from `users` where `users`.`id` = 1094' at line 1
at org.jooq_3.14.15.MYSQL.debug(Unknown Source)
at org.jooq.impl.Tools.translate(Tools.java:2903)
at org.jooq.impl.DefaultExecuteContext.sqlException(DefaultExecuteContext.java:757)
at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:389)
at org.jooq.impl.AbstractResultQuery.fetchLazy(AbstractResultQuery.java:453)
at org.jooq.impl.AbstractResultQuery.fetchLazy(AbstractResultQuery.java:422)
at org.jooq.impl.AbstractResultQuery.fetchLazyNonAutoClosing(AbstractResultQuery.java:436)
at org.jooq.impl.AbstractResultQuery.fetchOne(AbstractResultQuery.java:613)
at org.jooq.impl.AbstractResultQuery.fetchOne(AbstractResultQuery.java:565)
at org.jooq.impl.SelectImpl.fetchOne(SelectImpl.java:3034)
at org.jooq.impl.DAOImpl.existsById(DAOImpl.java:300)
at org.jooq.impl.DAOImpl.exists(DAOImpl.java:288)
The problem is that count has backticks. It should be select count(*) from `users` where `users`.`id` = ?
Has anyone run into this before and know how to fix it? TIA
You probably specified RenderQuotedNames.ALWAYS and ran into this problem? https://github.com/jOOQ/jOOQ/issues/9931
The setting ALWAYS is misleading. It really means literally always, though people probably read it as ALWAYSISH_I_E_ONLY_WHEN_IT_MAKES_SENSE. Probably a naming design error, but what you want is EXPLICIT_DEFAULT_QUOTED, see the documentation:
https://www.jooq.org/doc/latest/manual/sql-building/dsl-context/custom-settings/settings-name-style/
RenderQuotedNames
ALWAYS: This will quote all identifiers.
EXPLICIT_DEFAULT_QUOTED: This will quote all identifiers, which are not explicitly unquoted using DSL.unquotedName().
EXPLICIT_DEFAULT_UNQUOTED: This will not quote any identifiers, unless they are explicitly quoted using DSL.quotedName().
NEVER: This will not quote any identifiers.
COUNT in DSL.count()is an explicitly unquoted name, and ALWAYS will override that.
I am working on a project where I have to use Oracle Database 12c and I have to write all queries manually (so I can't use Spring Data).
For creating all tables and relationships, I use schema.sql and for template data I use data.sql.
And I have a problem with checking if table or data already exists.
In MySQL creating table would be like "create table if not exists".
In PL/SQL unfortunately, there is no equivalent for "if not exists". I replaced this functionality by:
begin
execute immediate
'CREATE TABLE user_data (
some data
)';
exception when others then if SQLCODE = -955 then null; else raise; end if;
end;
And it works when I run this script in SQL Developer or in Intellij's SQL console but the problem occurs when I want to run an application and Spring Boot tries to execute a script from schema.sql.
Output in terminal tells that:
nested exception is java.sql.SQLException: ORA-06550: line 8, column 4:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
* & = - + ; < / > at in is mod remainder not rem return
returning <an exponent (**)> <> or != or ~= >= <= <> and or
like like2 like4 likec between into using || multiset bulk
member submultiset
So it looks like Spring Boot doesn't know that it should run statement between "begin" and "end".
Any idea how can I manage the problem with database initialization ?
As a workaround, I could drop tables with every application run but it is not an optimal solution (and it wouldn't work when someone run the application for the first time).
Firstly, I would like to share two topics that seem to be relevant to this problem:
Unable to use "DROP TABLE IF EXISTS" in schema.sql for a Spring Boot application
executeSqlScript fails with Spring for PL/SQL block
There you will find a solution that should work: create a stored procedure and use in your schema.sql statement like
call recreate_table('USER_DATA','CREATE TABLE USER_DATA (SOME DATA)');
CALL statement is widely used across different databases, shortened to statement with only one semicolon and thus works well.
Secondly, I may only suppose, that the main problem is that anonymous blocks in PL/SQL (as well as other complex enough statements that may contain more than one semicolon) should be finished by a / character. I would recommend you to try to append this character to the end of your script, take a look at this and this answers, and if it does not work, create a stored procedure.
Also note that there is another way to check existence of the table (that comes over this wait for an exception pattern):
select count(*)
from user_tables t
where t.table_name = 'USER_DATA'
and rownum < 2
I'm trying to track the amount of redo being generated during a database session with the following query:
SELECT a.name, b.VALUE
FROM v$statname a, v$mystat b
WHERE a.statistic# = b.statistic# AND a.name = 'redo size';
This query works directly in SQL*Plus and Toad, but I get an ORA-00911 exception using JDBC, and I've narrowed it down to the "statistic#" column name.
How do I get around this?
The column name statistic# is not the problem.
My bet is that you also send the terminating ; from inside your Java program.
But you may not include the the ; when executing a SQL statement through JDBC (at least not in Oracle and some other DBMS).
Remove the ; from your SQL String and it should be fine.
put it in double quotes - that should let you call a field anything in Oracle
Switch on JDBC logging, check your driver documentation for how to do this. In the JDBC log you see the actual statement prepared and executed in the DB. This eliminates one possible cause for the error.
I am connecting to a DB2 database (DB2 v9.7.400.501) from my Java web application using the IBM DB2 Type 4 driver (db2jcc4.jar). When I try to execute an SQL statement like this,
SELECT * FROM USERS WHERE UPPER(USERNAME) = UPPER('testuser');
I get the following exception:
com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error:
SQLCODE=-104, SQLSTATE=42601, SQLERRMC=;;=
UPPER('testuser');END-OF-STATEMENT, DRIVER=4.12.55
The problem is from the UPPER function since, a normal select statement executes normally.
Maybe you should use is this way:
SELECT * FROM USERS WHERE UPPER(USERNAME) LIKE UPPER('testuser');
Your code with '=' is seems ok for SQLite but don't know anbout db2.
UPD. After some investigation, I can say that error is cause by Java code which tries to execute multiple statements in one query using ';' as a delimiter.
You should try using the PreparedStatement, addBatch() and executeBatch() for multiple statements.
UPD2. This is DB2 related issue. PostgreSQL, afaik, allows multiple statements in single query.
SEVERE: Local Exception Stack:
Exception [EclipseLink-7092] (Eclipse Persistence Services - 2.0.0.v20091127-r5931):
org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot add a query whose types conflict with an existing query.
Query To Be Added: [ReadAllQuery(name="Voter.findAll" referenceClass=Voter
jpql="SELECT v FROM Voter v")] is named: [Voter.findAll] with arguments [[]].
The existing conflicting query: [ReadAllQuery(name="Voter.findAll" referenceClass=
Voter jpql="SELECT v FROM Voter v")] is named: [Voter.findAll] with arguments: [[]].
I too have come across this issue and it makes little sense. I only have one entity bean with one defined query, and it continues to tell me it's the problem. I did a stop, then start of GF3, redploy my app, and I still get it.. and worse, I am not even using the query.
One thing I don't understand.. why is EclipseLink being used in GF? Is that part of GF? I use Eclipse IDE, but I don't deploy from within Eclipse.. I deploy from my ant build script at command line. I am guessing GF must be using some EclipseLink (used to be TopLink?).
One answer above said to make sure there are no stale files, undeploy app, etc. Would be great if someone that has figured this out could provide more details and explain it. If it is another query that has an error in it, sure would be nice if the error was shown instead of this misleading one.
So far, I've stopped GF, dropped all the tables, restarted, redeployed (in autodeploy folder), and still get this issue right away. I generally build/deploy to autodeploy folder several times in short periods of time, as I make quick changes then build/redeploy.
I encountered this problem also, I found out the exception isn't related with the error file at all, the problem is from another query for example:
#NamedQuery(name = "ChannelType.ALL", query = "SELECT channelType FROM ChannelType channelType WHERE channelType.applicationClient.applicationClientId =:applicationClientId ORDER BY channelType.channelTypId ASC")
the problem is from "ORDER BY channelType.channelTypId" its not except to order by primary key ,when I remove this line the exception just gone also.
Maybe someone else could explain why this happen.
Thanks
Just for the people out there that are still struggling with this error:
Undeploy your application and check if there are any stale (maybe locked) files left. This would cause the old namedqueries to still exist and thus not replacing them.
Delete the files and redeploy. The error should disappear.
Edit:
Also check if you haven't done anything like ... WHERE o.object_id = :id ... instead of ... WHERE o.object = :object ...
This was the solution for my problems. Took me 3 weeks to figure that out. EclipseLink isn't very clear when it comes to exceptions. There was actually a query compile error. Instead it throws a duplicate query exception.
It looks like you have the query defined twice. Either on the same entity, or on another entity, or in orm.xml
Not sure of what you're doing exactly since you're not showing any code but this is what EclipseLink documentation says about error ECLIPSELINK-07092:
ECLIPSELINK-07092: Cannot add a query whose types conflict with an
existing query. Query To Be Added:
[{0}] is named: [{1}] with arguments
[{2}].The existing conflicting query:
[{3}] is named: [{4}] with arguments:
[{5}].
Cause: EclipseLink has detected a conflict between a custom
query with the same name and arguments
to a session.
Action: Ensure that no query is added to the session more than once
or change the query name so that the
query can be distinguished from
others.
According to the above description and to the trace, it seems that you're adding a query (actually the same) with the same query name more than once to the session. You shouldn't (or use another query name).
also the error can come from a namedquery malformed, i had an where y o.activo -> that show me the specified error.
I had the problem...
The real Exception was a #Named Query malformed but the stacktrace just said:
"Exception Description: Cannot add a query whose types conflict with
an existing query"
My solution:
In the persistence unit change Table Generation Strategy to "None" and Validation Strategy to "None". When run again I obtained the real Exception (Malformed Query). I resolved the error in the query, returned to the old configuration in the persistence unit and all exceptions disappeared.
I'm going crazy but at least, this not works:
#NamedQuery(name = "xyx", query = "SELECT count(v) FROM Classe v WHERE v.id =:_id);
this works:
#NamedQuery(name = "xyx", query = "SELECT count(v) FROM Classe v WHERE v.id = :_id);
"WHERE v.id =:_id" was the error