What privileges does an oracle user need for spring batch? - oracle

I have a spring batch admin application. We recently tried to increase security by creating new oracle users with minimal privileges. After replacing the user for the spring batch application, I get this error.
exception: org.springframework.dao.DataAccessResourceFailureException: Could not obtain sequence value; nested exception is java.sql.SQLException: ORA-00942: table or view does not exist
After looking through the application and tomcat log, I've found that the application tries 3 times to execute this query before throwing the error.
SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? and JOB_KEY = ?
I tried this same query from sql developer, with the values stated in the log, and it came back with no results -but completed successfully. (no table not found error.)
I tried searching the log for instances of the same JOB_KEY, thinking there would be an insert statement, but i see none in this log.
Is there anyone familiar with Spring Batch that can help me verify what privileges the oracle user needs? Our new user does not have create or drop privileges. Can you help me verify that those are require, and why. -Meaning is it creating and dropping temporary tables? I tried to find this in the different log files but I've been unsuccessful so far.
Thanks!

The error indicates that it can't find a sequence value. That would lead me to believe that the new db id you have has access to the tables, but not the sequences. The Oracle schema for Spring Batch has three sequences it uses beyond the tables: BATCH_STEP_EXECUTION_SEQ, BATCH_JOB_EXECUTION_SEQ, and BATCH_JOB_SEQ.

Please check your context.xml file for proper Database Type.It could be you are using My/Sql in Code whereas actual DB is Oracle.
property name="databaseType" value="oracle"

Related

"autoKeyInfo is not initialized" when trying to batch insert into table with generated id

When I tried to upgrade my Oracle JDBC driver from ojdbc8 19.6.0.0 to ojdbc11 21.6.0.0.1 I started to receive the following exception when trying to do a batch insert with ids being generated in the database:
java.lang.AssertionError: autoKeyInfo is not initialized
I created a reproducer for this.
How can I resolve this problem?
This seems to be a bug in the later versions of the Oracle JDBC drivers.
They have the findings in the issue tracker, but I have nothing to link to since it is not public.
The recommended workaround is to use the LTS driver version, which is ojdbc 19.15.0.0.1
The reproducer is not just doing a batch update, it uses a Keyholder and tries to return the IDs generated by the database. The problem is not the generation of values, the problem is the attempt to return them.
https://docs.oracle.com/en/database/oracle/oracle-database/21/jjdbc/Oracle-extensions.html#GUID-9EC82134-1206-4325-A17B-9FA7610F0169 says "DML returning cannot be combined with batch update". "DML returning" refers to "returning into" clauses used by the driver to return values for out parameters. Looks like a conscious regression in the newer driver versions. Spring uses Keyholders to handle out parameters.
When creating the keys in the database with identity columns or triggers or with <sequence>.nextval in the SQL statement and not trying to return it the generated value, batch inserts should work.

What is the way to list all created users in h2 memory database spring boot

I am running some unit tests using in memory h2 database in spring boot application. Meanwhile interacting with in memory h2 database, I have created some users and grant them some permissions. I can see users are being created successfully (I am assuming it because command gets executed successfully without any issue and grant privileges command also gets executed successfully.). I want to list all existing users that exist in database currently and want to assert results with those users that are created by me.
I know we list all users in mySql database using database query:
select * from mysql.user
I just want to achieve same thing but with in memory h2 database. Does anyone know how can I get list of all users in h2 in memory database.
I am trying this query select * from users but system throws exceptions indicating users table doesn't exist. Is there any way to get all users in h2 database?
I have tried show command but show tables list only those tables that are created by my application. I am not creating any user table myself, I am assuming h2 in memory will have any table persisting users information just like mysql.user table. show schemas also show my database is already created in h2 memory database.
Thank you.
As worked out in comments: you do find the USERS table under the INFORMATION_SCHEMA schema. Therefore you must query:
select * from INFORMATION_SCHEMA.USERS;
The way, DBMS organize their internal configuration is quite different from DBMS to DBMS. In mysql as you stated, there is the users table in mysql.users (at least for MariaDB as far as I know) and for H2 the same is at INFORMATION_SCHEMA.USERS.

Unable to update hive table via JDBC

I am unable to do an Update to my hive table via JDBC. I able to Select, but not Update.
Connecting to the hive database:
Connection connection =
DriverManager.getConnection("jdbc:hive2://localhost:10000/db", "", "");
My query:
ResultSet resultSet = statement.executeQuery("update db.test set name='yo yo' where id=1");
Stacktrace:
java.sql.SQLException: Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.MoveTask
at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:275)
at org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:355)
at com.spnotes.hive.App.main(App.java:63)
Again, I am able to Select but not Update via JDBC. I am however, able to Update my table via the hive shell only. I believe this is a user permissions issue. I have seen other problems where an HDFS directory needed to be granted permissions before it could be written to.
I had to invoke my hive shell with my HDFS user as so:
sudo -u hdfs hive
Can I somehow pass a "hfds" user via JDBC? It does not look like this is possible. This is how I'm thinking the exception will not happen anymore.
Here is the "secure way" of passing in a username and password as so:
Connection con = DriverManager.getConnection("jdbc:hive2:/hiveserver.domain.com:10000/default;user=username;password=password");
BUT this is NOT the same thing as passing the user hdfs. Perhaps it is possible to link the "username" with permissions to update the hive table?
Any help is welcome. Thanks!
You are trying to pass a update statement in a executeQuery()
For security reasons, any update statement will fail when using this method. Change it to executeUpdate()
Also, instead of using queries like this, I suggest using Prepared Statements, since by using parameters you make it less vulnerable to SQL Injections

Create database in oracle for manually created user

I want to create the user and the database within that user. But when I tried to create database its giving the warning message as
ERROR at line 1:
ORA-01501: CREATE DATABASE failed
ORA-01100: database already mounted
Then I tried
STARTUP NOMOUNT;
Its giving the warning message for insufficient privileges even I have given all the permission to that particular user.
Can any one please help in finding the solution for this?
You don't create a database under a user in Oracle; I believe you're using terminology from another database poduct. The equivalent is a schema, which is a logical container for a group of objects. User and schema are essenentially synonymous in Oracle - when you create a user is automatically has its own schema.
You create the database once (which you already seem to have done, or had done for you), then create as many schemas/users as your application needs. You don't ever rerun the create database under normal circumstances - you certainly wouldn't as a normal user.
If you connect as that user you will be able to create tables, views, packages etc., assuming it has really been granted all the necessary privileges.

What causes a JDBC Type 91 error?

I have a web app hosted on BEA Weblogic 10.x with an Oracle 10g database backend.
It works perfectly with one database, but when we make a clone of it and try to use a different WebLogic and Oracle instance we are getting this error:
ERROR - Problem initializing invocation tracking - disabling
tracking xxxxclass.BadTableMappingException: Database column
xxxxPeriodEnding in database yyyyyyy, table zzzzzzz has an
unknown type: JDBC Type 91.
We get it every time we do a query that involves a column of type DATE. There was no ORA-XXXX code in the message.
I can access the database using SQL*Plus using the same access and do selects and updates on the same tables with no errors.
The answer to this question is not just a simple description of what a type 91 error is (although that will help) but what could be causing this given the circumstances described above.
I am using ojdbc14.jar for JDBC on both instances of weblogic.
I have no idea about the error, but have you considered the jdbc jar version and more importantly if the oracle DB needs to be updated.
I faced very weird problems with oracle, and struggled for a while to find at the end that installing some patches for oracle would solve the problem.
Set oracle.jdbc.V8Compatible=true.
This remaps the oracle DATE type to a DATETIME time in JDBC. This parameter was missing on the new Weblogic server.

Resources