Below is my query which works fine in pgAdmin
UPDATE data SET data = data - 'dateAdded' || '{"dateAdded":1481500800000}'
WHERE dtype='Customer' and data->>'id' = '00784591'
The same query throws an error from my Spring Boot application.Below is the error:
StatementCallback; uncategorized SQLException for SQL [UPDATE data SET
data = data - 'dateAdded' || '{"dateAdded":1481500800000}'
WHERE dtype='Customer' and data->>'id' = '00784591']; SQL state [S0001];
error code [102]; Incorrect syntax near '|'.; nested exception is
com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near
'|'.
Please note that I am running other select queries too from my application and they work fine. Its just this one that fails. I am using jdbcTemplate and calling update method on jdbcTemplate to run this query. Can you point out the issue?
Related
Trying to execute the following code :
this.getSessionFactory().getCurrentSession()
.createNativeQuery("SET app.variable = :variable")
.setParameter("variable","variableValue")
.executeUpdate();
It is giving me the following error :
org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"
Position: 26
I'm not sure if this is a bug in JDBC or PostgreSQL.
It seems not a PostgreSQL issue as when I use the DBeaver using bind variables the query works fine.
Tried the same query by creating a prepared statement as well and the Result was same.
The SQL statement SET accepts no parameters. Only SELECT, VALUES, INSERT, UPDATE, DELETE and MERGE do.
Currently in one of our application we are getting below error :
org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback; uncategorized SQLException for SQL [{call test_pkg.set_user_details(?)}?)}]; SQL state [99999]; error code [17041]; Missing IN or OUT parameter at index:: 2; nested exception is java.sql.SQLException: Missing IN or OUT parameter at index:: 2
Procedure Body :
PROCEDURE set_user_details(ID NUMBER DEFAULT -1)
IS
BEGIN
//
//
END set_user_details;
There is no issue in Java or DB code. Same code is working since long time and there is no recent change.
From Java code we are passing single parameter to that stored proc.
This is an intermittent issue. It happens only when we restart the server. As per my knowledge this is happening because if we do any transaction during server startup,
DB and application can be in different state and those 2 will not be in sync. Please correct me if I am wrong.
My question is, if its a state related issue, then why its giving Missing IN or OUT parameter at index:: 2 instead of giving state related error\exception ?
Also, even though that stored proc accept only one param , that exception says parameter is missing at index 2. Why its expecting param at index 2 ?
Currently we are using Oracle 12c and using JdbcTemplate to execute stored proc
Thank you
It's an issue with the prepared statement, it's [{call test_pkg.set_user_details(?)}?)}]; but definitely should be [{call test_pkg.set_user_details(?)}]; - somehow the part ?)} gets doubled...
I am using query
select x
from table1 x
order by x.it desc
It is working good when I use it with Postgres but whenever i change the database and start to use oracle it is throwing an error that is,
ERROR -- ORA-01722: invalid number
org.hibernate.exception.SQLGrammarException: could not execute query
Using Java Spring Batch, I am generating a file based off of a query sent to a Oracle database:
SELECT
REPLACE(CLIENT.FirstName, chr(13), ' ')
FROM client_table CLIENT;
This query works fine when I run it in Oracle SQL Developer when I spool the result, but doesn't work when I try to utilize it to generate a file in Java Spring batch. It throws the error:
Message=Encountered an error executing step preparePrimaryIpData in job extract-primary-ip-job
org.springframework.jdbc.BadSqlGrammarException: Attempt to process next row failed; bad SQL grammar [
SELECT
REPLACE(CLIENT.FirstName, chr(13), ' ')
FROM client_table CLIENT
]; nested exception is java.sql.SQLException: Invalid column name
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:237)
Why is this working fine in Oracle Sql Developer but not when I try to utilize it in Java Spring Batch?
Also, the alias is necessary, because my actual query has a lot more joins, I just wanted to simplify it as an example.
you need to check the spelling of columns in your query as well as where you will be getting the result set. I was facing the same problem and the problem was in spelling in one of the "rs.getString("COLUMN_NAME")".
It is not the sql that has failed but you are misspelling the column name somewhere in your code.
Try some thing like :
SELECT REPLACE(CLIENT.FirstName, chr(13), ' ') columnNameX FROM client_table CLIENT
Getting exception while running this query
select COUNT(tl.LOG_ID)AS EVTCOUNT,tl.PRIORITY FROM Customer_? tl Where tl.DEVICE_REPORTED_TIME >= SysDate-90 GROUP BY tl.PRIORITY ORDER BY tl.PRIORITY`
Here I am using query.setLong(0,custId);
so it will become like Customer_1
If I run the above query from SqlDeveloper IDE It is working fine or If I set this value as Statically like Customer_1 instead of Customer_?
It working fine.
Errors:
WARN : org.hibernate.util.JDBCExceptionReporter - SQL Error: 933, SQLState: 42000
ERROR: org.hibernate.util.JDBCExceptionReporter - ORA-00933: SQL command not properly ended
What Might be wrong with this query though other queries are running fine?
Edit
I am using NamedQueries and I have written this query in a separate xml file.
You can't use a parameter in a query like that. Without going into the logic behind this, your best option is to concatenate the query string before creating a query
String queryString = "select COUNT(tl.LOG_ID) AS EVTCOUNT,tl.PRIORITY FROM Customer_" + custId + " tl Where tl.DEVICE_REPORTED_TIME >= SysDate-90 GROUP BY tl.PRIORITY ORDER BY tl.PRIORITY";
Query query = session.createSQLQuery(queryString);
EDIT
As for NamedQueries, they are compiled when the application is started so I don't think there is a way to change the target entity (table) at runtime.