Oracle 11g schema selection - java

I have analyzing an code of application implemented Java SE (Spring) and Oracle 11g. In XXXDaoImpl class there are many queries writte as
select * from PREFIX.TableName
I have created a schema in oracle 11g via Oracle SQL Developer and imported all tables successfully.
But when an application tries to call any procedure it call MYPREFIX extention lets say
select * from MYPREFIX.TableName
I would like to know how to change the MYPREFIX name in SQL Developer to get code and newly created schema similat each other in order to run the application properly.
I am currently having following error.
ERROR 30 May 2013 18:06:02,036 [ChangeDeleteMHandler] [ChangeDeleteMHandler]: Error during change/delete msisdn procedure call
org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback; uncategorized SQLException for SQL [{call TABLENAME.changeM()}]; SQL state [72000]; error code [4063]; ORA-04063: package body "PREFIX.TABLENAME" has errors
ORA-06508: PL/SQL: could not find program unit being called: "PREFIX.TABLENAME"
ORA-06512: at line 1
; nested exception is java.sql.SQLException: ORA-04063: package body "PREFIX.TABLENAME" has errors
ORA-06508: PL/SQL: could not find program unit being called: "PREFIX.TABLENAME"
ORA-06512: at line 1
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:969)
at org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1003)
at org.springframework.jdbc.object.StoredProcedure.execute(StoredProcedure.java:125)

Chances are PREFIX and MYPREFIX as Oracle Schema users, so in your scenario your application is accessing tables under the PREFIX schema and you've created a new MYPREFIX schema. If that's the case, you could grant privileges to your schema by running under the PREFIX:
GRANT SELECT, INSERT, UPDATE, DELETE ON YOUR_TABLE
TO MYPREFIX;

Related

PostgreSQL, Atomikos and PREPARE transaction

I stack with next problem: my application which consist of Tomcat 8, Java 11, Spring 5, Atomikos 5, PostgreSQL 9.3.5 throw some strange errors. In Spring Repository I have method, which run native SQL query with temp tables creating and then perform some SELECTs. And at first method call I have next log output:
Hibernate: /* dynamic native SQL query */ DROP TABLE IF EXISTS all_character; CREATE TEMP TABLE all_character AS (...); DROP TABLE IF EXISTS character_last_cut;
Hibernate: /* dynamic native SQL query */ SELECT * FROM ( SELECT sort_num ...
Hibernate: /* dynamic native SQL query */ DROP TABLE IF EXISTS character_last_cut_ch_column;
15:52:45,284 ERROR XAResourceTransaction:66 - XA resource 'commonDataSource': prepare for XID 'XID: 3139322E3136382E302E3130322E746D313631373336343336353139373030303532:3139322E3136382E302E3130322E746D3532' raised -7: the XA resource has become unavailable
org.postgresql.xa.PGXAException: Error preparing transaction. prepare xid=XID: 3139322E3136382E302E3130322E746D313631373336343
...
Caused by: org.postgresql.util.PSQLException: ERROR: cannot PREPARE a transaction that has operated on temporary tables
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2553)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2285)
and it's right in accordance with "It is not currently allowed to PREPARE a transaction that has executed any operations involving temporary tables, ..." - https://www.postgresql.org/docs/9.3/sql-prepare-transaction.html
But at the next method calls all work fine without any errors. Why that error throwed only at first method call and not throwed by followed calls?

DB2 SQL Error: SQLCODE=-551, SQLSTATE=42501 [duplicate]

I am having problem with DB2. I just installed the db2 as a db2admin and with a password. When i try to connect to database it is success full and while running any simple select query it give me following error:-
DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=DB2ADMIN.LOGIN, DRIVER=3.57.82
I have a database named onp and a table in it called 'login' in which there is one table called 'login' with two fields username and password.
Query that i am running
Select * from login; gives me error
DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=DB2ADMIN.LOGIN, DRIVER=3.57.82
Select * from system.login; gives me error:- (//system is schema name)
DB2 SQL Error: SQLCODE=-551, SQLSTATE=42501, SQLERRMC=DB2ADMIN;SELECT;SYSTEM.LOGIN, DRIVER=3.57.82
I have tried all the resources on the net and exhausted completely. Please help me
I don't know a lot about DB2, but looking up the error codes...
The first error is because you didn't specify a schema, so it couldn't find the login table.
SQLCODE -204 Object not defined to DB2
DB2 apparently requires you to specify the schema name or it looks in the schema with the same name as your login user.
You must use SET SCHEMA or fully qualify the table name.
The second error is because you don't have the privileges to perform that select:
SQLCODE -551, Error: DOES NOT HAVE
THE PRIVILEGE TO PERFORM OPERATION ON
OBJECT
I'm not sure why the db2admin user wouldn't be able to select from this table...
Resources:
List of DB2 SQLCODEs
SQL CODE 551 occurred because the connecting user does not have privileges to perform operations.
Go to Control Center - Go to User Group and Object and select DB2ADMIN(assume this user is the one use to connect to DB2)
Check all the check box as the following
Grant Schema access to the user
Grant Tables access to the user
I had the same problem and i resolved it by adding Schema in my entity :
#Entity
#Table(name="MyTable", schema="MySchemaName")
public class MyClass implements Serializable {
...
}
You can also resolve the issue as:
Just give the proper authority to the user by which you are connection to DB2.

Using parameter markers with DB2 for z/OS's encryption syntax in Spring

Trying to use a Prepared Statement so I don't have to deal with messy conversions or worry about injection, but it doesn't seem to be possible when encrypting columns in DB2 for z/OS on an insert.
Here is a sample of what kind of error I get when attempting an insert:
PreparedStatementCallback; bad SQL grammar [insert into CONTENTSOURCE (CONTENTSOURCE_ID, CS_NAME) values (?, ENCRYPT(?))]; nested exception is com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-418, SQLSTATE=42610, SQLERRMC=null, DRIVER=4.12.55
Edit*: So, putting ENCRYPT(CAST(? as VARCHAR(1048) FOR BIT DATA)) in appears to work. But I'm running into a problem with batch updates. The same query that works for a single insert gives
com.ibm.db2.jcc.a.io: Error for batch element #1: VARIABLE IS NOT DEFINED OR NOT USABLE
as an error when attempting the batchExecute

Strange error running query using ejb3 /hibernate

I am having the following statement.
result = (BigDecimal)m_EntityManager.createNativeQuery(query).getSingleResult();
Query is:
select sum(field5) from myTable where field1 = '?#This' and
field2=1234 and field3 IN ('7183328608','7187931685','7187931686')
Hibernate version is: 3.2.1ga
When ran against development and QA servers, we are having no problem
However, when deploying to production, there is an exception/error is observed.
ERROR: [BillSessionEJB: ] Error in runSingleResultNativeQuery(): running query:
select sum(field5) from myTable where field1 = '?#This' and
field2=1234 and field3 IN ('7183328608','7187931685','7187931686')
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not
execute query javax.persistence.PersistenceException:
org.hibernate.exception.SQLGrammarException: could not execute query
at org .hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:99)
at com.broadview.billing.billingdataservices.beans.BillSessionEJB.runSingleResultNativeQuery(BillSession
Development and QA server are running SQLSERVER 2012, Production is running 2005. Is there a difference?
My only thought is that to put a name for the column sum.
as 'Total' .. in select
Any comments, ?? Please share thoughts.
Your query seems ok. Are the column names correct? The documentation of SQLGrammarException hints that:
Implementation of JDBCException indicating that the SQL sent to the database server was invalid (syntax error, invalid object references, etc).
So the syntax is just one of the possible culprits. Try to run your query by hand on production and see what the DB tells you.

SQL - UPPER function in DB2 not working

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.

Categories

Resources