Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2014
    Posts
    294

    Answered: DB2CMD.exe authority

    Hi ,
    I have created one Db2 java procedure to start the db2 command window.
    Below is my statement to connect :


    String[] command = {"DB2CMD.exe", "db2 connect to orange", "db2 call sp_sipla('poppy','poppyih','DB2/UDB',1000)"};
    Process p = Runtime.getRuntime().exec(command);

    Using this I can start db2 command window & call the procedure. Here I am connected as SYSADMIN (poppy).

    Now There is one more user & i am trying to use the same statement with that user

    String[] command = {"DB2CMD.exe", "db2 connect to apple user YUK using umbrella", "db2 call sp_sipla('umber','umber','DB2/UDB',1000)"};
    Process p = Runtime.getRuntime().exec(command);

    Here I am not able to connect to db2 command window.

    I have added that user to admin group & guven necessary privileges too.

    Can some one suggest me what I am missing here .

    Thanks

  2. Best Answer
    Posted by mark.b

    "Hi,

    If you use DB2 Extended Security the user who runs db2 commands must be a member of DB2USERS group at least.
    To can check if you use it running the following:
    Code:
    db2set DB2_EXTSECURITY
    If you don't use it - there are no special privileges required to run db2cmd.

    If you have "dynamic" database connection, you can use OS system variables.
    For example, you can create a bat file with the following contents:
    Code:
    db2 connect to %mydb% user %myuser% using %mypwd%
    db2 call sp_sipla('%my_par1%','%my_par2%','DB2/UDB',1000)
    db2 connect reset
    db2 terminate
    Then you can initialize these variables externally (in another bat file or manually) before running the above file.

    You can even avoid using db2cmd by specifying the system environment variable DB2CLP like this:
    DB2CLP=**$$**
    You can run any db2 command in the standard cmd.exe afterwards."


  3. #2
    Join Date
    Jul 2013
    Location
    Moscow, Russia
    Posts
    666
    Provided Answers: 55
    Hi,

    Let's start from your goal.
    What do you try to achieve?
    Where did you find such a strange way of db2 connectivity from java?
    Why don't you work with db2 via standard jdbc calls?

    Regarding to your question:
    try to run from a standard cmd.exe window:
    > db2cmd "db2 connect to apple user YUK using umbrella" "db2 call sp_sipla('umber','umber','DB2/UDB',1000)"
    Does it work? No, it doesn't because it's completely wrong call.

    If you want to use db2cmd, try this.
    Create a file myfile.sql with the following 3 rows:
    Code:
    connect to apple user YUK using umbrella;
    call sp_sipla('umber','umber','DB2/UDB',1000);
    connect reset;
    and call it like this from the catalog with the myfile.sql:
    Code:
    db2cmd /i /w /c db2 -tvsf myfile.sql -z myfile.sql.log
    look in the myfile.sql.log file for the messages.

    But don't use exec runtime java calls for that.
    Regards,
    Mark.

  4. #3
    Join Date
    Jul 2014
    Posts
    294
    Hi Mark,

    Thanks for the reply. I don't know even basics in java at all. I read some docs & tried the following code.
    String[] command = {"DB2CMD.exe", "db2 connect to orange", "db2 call sp_sipla('poppy','poppyih','DB2/UDB',1000)"};
    Process p = Runtime.getRuntime().exec(command);

    Using this I can connect to the desired database orange & able to run the procedure too . I can find the output once it is done.

    Regarding what you stated above :

    try to run from a standard cmd.exe window:
    > db2cmd "db2 connect to apple user YUK using umbrella" "db2 call sp_sipla('umber','umber','DB2/UDB',1000)"
    Does it work? No, it doesn't because it's completely wrong call.

    This is not working as it is taking as a direct single statement.
    But IF I ran the above statement in a splitted way as
    >db2cmd
    >db2 connect to apple user YUK using umbrella
    >db2 call sp_sipla('umber','umber','DB2/UDB',1000)

    These three individual steps are working fine.

    And thanks for the way you specified to connect to the database through sql file.In my scenario I can't use a sql file because the connection to a database is dynamic.
    Can you kindly tel me what are all the privileges required to start db2cmd.exe from a non admin db2 user.
    Last edited by HABBIE; 03-23-15 at 03:10.

  5. #4
    Join Date
    Jul 2013
    Location
    Moscow, Russia
    Posts
    666
    Provided Answers: 55
    Hi,

    If you use DB2 Extended Security the user who runs db2 commands must be a member of DB2USERS group at least.
    To can check if you use it running the following:
    Code:
    db2set DB2_EXTSECURITY
    If you don't use it - there are no special privileges required to run db2cmd.

    If you have "dynamic" database connection, you can use OS system variables.
    For example, you can create a bat file with the following contents:
    Code:
    db2 connect to %mydb% user %myuser% using %mypwd%
    db2 call sp_sipla('%my_par1%','%my_par2%','DB2/UDB',1000)
    db2 connect reset
    db2 terminate
    Then you can initialize these variables externally (in another bat file or manually) before running the above file.

    You can even avoid using db2cmd by specifying the system environment variable DB2CLP like this:
    DB2CLP=**$$**
    You can run any db2 command in the standard cmd.exe afterwards.
    Regards,
    Mark.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •