db2 CREATE DATABASE XYZ
db2 DROP DATABASE XYZ
These db2 commands which doesn't provide support to specify username/password while executing on db2cmd/db2clp for a specific user other than machine logged-in user. Hence result a exception
"SQL1092N The requested command or operation failed because the user ID does not have the authority to perform the requested command or operation."
And when the same commands run as by choosing 'Run as different user', it works properly.
- But I need to use same mechanism from Java code, but don't know how. Is it possible to open installed db2's clp as a different user form Java code??
- Is it possible to associate username/password in create/drop commands?
From the CLP you can first ATTACH
to the instance using whatever user ID you need, and then issue the CREATE DATABASE
command.
If the instance is running on your local machine, you just attach like this:
$ db2 attach to db2inst1 user db2inst1
Enter current password for db2inst1:
Instance Attachment Information
Instance server = DB2/LINUXX8664 9.7.5
Authorization ID = DB2INST1
Local instance alias = DB2INST1
If the instance is running on a remote server, you attach to the "node name" that you have defined in your database catalog:
$ db2 list db directory
System Database Directory
Number of entries in the directory = 1
Database 1 entry:
Database alias = SAMPLE
Database name = SAMPLE
Node name = SRV01
Database release level = d.00
Comment =
Directory entry type = Remote
Catalog database partition number = -1
Alternate server hostname =
Alternate server port number =
In this example, the Node Name shown in the output from list database directory
is SRV01
, so you would attach using: db2 attach to srv01 user <username>
.