create db2 schema using jdbc - sql

What is the correct syntax or what are the correct steps for creating a schema in DB2 using JDBC?
When running create schema test1 or create schema test1 authorization db2admin as db2admin, I consistently get DB2 SQL Error: SQLCODE=-552, SQLSTATE=42502, SQLERRMC=DB2ADMIN;CREATE SCHEMA, DRIVER=3.64.106
The exact same command works fine using the DB2 command-line tools.

I found it.
It turns out that for some reason DB2 Express-C does not grant the DBADM privilege to db2admin by default.
This can be fixed by connecting to the DB and then issuing
GRANT DBADM ON DATABASE to db2admin
Thanks Ian Bjorhovde for providing the inspiration spark!

Looks like it is not a matter of Syntax but authentication, you have to check the credentials that you are passing through JDBC:
-552 authorization-id DOES NOT HAVE THE PRIVILEGE TO PERFORM OPERATION operation
http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=%2Fcom.ibm.db2z9.doc.codes%2Fsrc%2Ftpc%2Fn552.htm

Related

Unable to load dataset using IBM DB2 LOAD tool

Error for batch element #1: "WQX79824" does not have the privilege to perform operation "IMPLICIT CREATE SCHEMA".. SQLCODE=-552, SQLSTATE=42502, DRIVER=4.26.14
Number of occurrences: 1
This is not a programming issue, instead it is a configuration issue.
Either ask your DBA to grant the relevant authority and permissions to the authID you use (WQX79824) to connect to the database, or alternately connect to the database with a different authID which already has the required permissions and authorities to create objects and do loads etc.

How to solve ERROR: must be member of role "postgres"

I am very new to postgres. One of my project is using an RDS postgres instance, the application team created a user and use that user to create the database.
I am trying to grant default privilege to the default postgres user to this application database by running the command below but I am getting an error message.
ALTER DEFAULT PRIVILEGES
FOR USER postgres
IN SCHEMA public
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO postgres;
Error message
ERROR: must be member of role "postgres"
SQL state: 42501
Please advise how I can grant default privilege to postgres user for the database.
You must connect as a superuser to run this command.
I misunderstood my case earlier. Apparently, postgres user was the owner of the database not the app user. So I logged in as postgres and executed the command and it works.
If you did a pgdump to export the database, and then were getting this error on trying to import it. Use -O when creating the pgdump - https://www.postgresql.org/docs/current/app-pgdump.html

How to create database table when using Wildfly?

I am trying to complete a tutorial on a simple javaEE project using wildfly. The first step is creating two tables in my database. As it says I should create my tables like this: "CREATE TABLE wildfly.name...." but it gives me an error saying thet wildfly is unknown.
Link to the tutorial: click here
My question is why should i put "wildfly." before the table name and how can I solve this error?
Thank you for your help!
Note: I am using oracle database instead of mysql
It's a misleading MySQL tutorial example because in Oracle syntax "wildfly." is a user(schema) in the Oracle database.
Schema/user in Oracle is a namespace for tables and other objects. So, when you issue such a statement - you're telling oracle to create table in namespace WILDFLY. If you don't have such user in your database or you don't have rights to access such user/schema - you can't create tables there.
You should create such user in Oracle database (or alter your statement to another user/schema name that you actually have in your database) and put your tables there.
For example these statements are correct because I created WILDFLY user before putting tables to it:
CONNECT SYS/****#ORCL AS SYSDBA
CREATE USER WILDFLY IDENTIFIED BY WILDFLYPASSWORD;
GRANT UNLIMITED TABLESPACE TO WILDFLY;
CREATE TABLE WILDFLY.MYTABLE...

Why "SQL> show parameter processes" command is not working?

I am using oracle 10g express edition. I ran the command in sql command line and it says -- "ORA-00942: table or view does not exist"
PS: Trying to access and increase the number of processes. Cause I am facing this problem -- How to solve ORA-12516 error?
You're probably running this command as a non-privileged user. show parameter is just a fancy wrapper for select ... from v$parameter. You need SELECT privileges on this view:
grant select on v_$parameter to <username>;
(please note the _ in the view name - you cannot directly grant privileges on v$ views, you have to grant privileges on the underlying objects instead).
Of course, the simplest approach is to run show parameter as a DBA user.

Cannot find table v$parameter in Oracle

I want to get the number of sessions in Oracle using the SQL query:
SELECT value FROM v$parameter WHERE name = 'sessions'
But I get this error:
Error starting at line 1 in command:
SELECT value FROM v$parameter WHERE name = 'sessions'
Error at Command Line:1 Column:18
Error report:
SQL Error: ORA-00942: table or view does not exist
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Maybe the Oracle user that I use is not privileged?
Generally the better approach is to use a procedure and grant the necessary privileges to this procedure. However if you want use SQL directly, you can grant SELECT_CATALOG_ROLE or SELECT ANY DICTIONARY to the user.
Probably. To grant the rights, you need to use the table name as V_$PARAMETER. It comes from some restriction when granting rights on dynamic views.
If you want to use SQL directly (referring to the second option in the accepted answer)
As of Feb 2023, using Oracle version 19, this works...
Connect as SYSTEM and run
grant SELECT ANY DICTIONARY to <user>;
But SELECT_CATALOG_ROLE didn't work for me...
grant SELECT_CATALOG_ROLE to ...;
There are documented differences between the two here:
http://www.petefinnigan.com/weblog/archives/00001461.htm
This is where the author gives the following info and warning:
Well, SELECT_CATALOG_ROLE allows access to some things Oracle deemed not allowed by SELECT ANY DICTIONARY so we need to be careful of granting this role on these grounds. BUT, the overwhelming issue for me is that SELECT_CATALOG_ROLE gives access to 4539 objects and SELECT ANY DICTIONARY gives access to 6228 objects (both numbers in 18c XE)
I am not sure why Oracle do not publish the full list of exclusions in SELECT ANY DICTIONARY but they do publish all of the main tables. We can easily find out anyway. For me, i want to know what does SELECT ANY DICTIONARY really mean. I want to know what i am actually granting if I give out that privilege; well it means access to 6228 tables and views in 18cXE
Both of these rights should not be used; they are a sledgehammer to crack a peanut. If someone needs access to V$SESSION or V$DATABASE and there is a legitimate reason to have that access then grant access on the individual views not SELECT ANY DICTIONARY or SELECT_CATALOG_ROLE.
using the privileges: - select any table, alter any table when running the grant as SYS with SYSDBA in Oracle 12c solved the issue for me.