How to grant privileges to current user

1.5k views Asked by At

I'm trying to make a java application that uses a database. I've downloaded db2 and created a user 'student'. I have the following lines in my program:

con = DriverManager.getConnection(url, "student", "xxxxxx"); 

and

ResultSet rs= stmt.executeQuery("SELECT sifra, naziv " +
                        " FROM predmet " +
                        " WHERE bodovi > 20" );

And the second one throws a SqlSyntaxErrorException with the following message: DB2 SQL Error: SQLCODE=-551, SQLSTATE=42501.

So I looked it up and it seems that the user doesn't have the required level of privilege. So when I tried to run the query in db2 command line, I got:

The statement failed because the authorization ID does not have the required authorization or privilege to perform the operation. Authorization ID: "STUDENT". Operation: "SELECT".

So since obviously I barely know what I'm doing, I don't know how to grant 'student' the necessary privileges. That is, I don't know what user could give him the privileges since I never created another user. I've seen 'db2admin' mentioned (I'm using windows), but I don't know what to do with that piece of information. I don't know how to check the existing users or which password to use for db2admin (if that's even possible).

1

There are 1 answers

0
GeekyDaddy On

If you wish for this user to have access you need to determine at what level: Server, Instance, Database, Table, etc. Here is an article about DB2 Granting and various levels.

To make it easy, let assume this user will have full database privileges and we'll use GRANT DATABASE

GRANT ACCESSCTRL, BINDADD, CONNECT, CREATETAB, CREATE_EXTERNAL_ROUTINE, 
    CREATE_NOT_FENCED_ROUTINE, DATAACCESS, DATAACCESS, EXPLAIN, 
    IMPLICIT_SCHEMA, LOAD, QUIESCE_CONNECT, SECADM, SQLADM, WLMADM ON 
    DATABASE DB_STUDENT TO student;