Results 1 to 15 of 15
  1. #1
    Join Date
    Sep 2012
    Posts
    16

    Unanswered: Run create/drop DB2 database commands for a specific user other than machine logged-i

    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.

    1. 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??
    2. Is it possible to associate username/password in create/drop commands?

  2. #2
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    according the doc : create db
    Instance. To create a database at another (remote) database partition server, you must first attach to that server. A database connection is temporarily established by this command during processing.
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

  3. #3
    Join Date
    Apr 2012
    Posts
    1,035
    Provided Answers: 18
    I'm sure that a recent DB2 for LUW release lets you create a database directly from jdbc (without using clp). I can't find the link at present but I know it's been added.

    Failing that, is'nt there a class that wraps the 'runas' feature (if you are using Windows), or sudo (if using a linux/unix distro).

  4. #4
    Join Date
    Sep 2012
    Posts
    16
    I just want to ask you that if no database created initially (first time), then how would I then use jdbc for Create database command.
    Reason: JDBC connection can only be established, if u specify a database name in connection URL, after then u can use statements to create tables/procedures etc, but if not database is there (initially), then how u will use JDBC?
    Last edited by rahulsri; 09-05-12 at 10:15.

  5. #5
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    google returned this link
    JDBC - Create Database Example
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

  6. #6
    Join Date
    Sep 2012
    Posts
    16
    Statement statement = connection.createStatement();
    statement.executeUpdate("CREATE DATABASE ABC ON 'C:' DBPATH ON 'C:'");

    The following exception comes while executing the above query:

    com.ibm.db2.jcc.am.io: An unexpected token "DATABASE" was found following "CREATE ". Expected tokens may include: "STOGROUP".. SQLCODE=-104, SQLSTATE=42601, DRIVER=3.57.82

  7. #7
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    IBM invented the online infocenter : please have a look.. it is for free.....
    CREATE DATABASE command
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

  8. #8
    Join Date
    Sep 2012
    Posts
    16
    I already know this command properly. And if I run same create database command on db2cmd/db2clp,

    "CREATE DATABASE ABC ON 'C:' DBPATH ON 'C:'"

    it works and creates database successfully.

  9. #9
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Quote Originally Posted by rahulsri View Post
    I already know this command properly. And if I run same create database command on db2cmd/db2clp,

    "CREATE DATABASE ABC ON 'C:' DBPATH ON 'C:'"

    it works and creates database successfully.
    In DB2, "CREATE DATABASE" is a command, not a SQL statement and cannot be used with JDBC.

    Andy

  10. #10
    Join Date
    Oct 2008
    Posts
    82
    Yes ARWINNER is correct .. We cannot use commands in JDBC

  11. #11
    Join Date
    Mar 2011
    Posts
    9
    przytula_guy & rameshj6, you both don't understand the RahulSri question.

    He is just asking how to create database in DB2 using another user ID, apart from logged-in user

    but firstly you replied to use JDBC (with an Mysql create database example),

    now you again saying CREATE DATABASE is not a JDBC command, even we all know DB2 doesn't support database creation feature in JDBC URL.

    I think u all guys not focusing the problem?

  12. #12
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    as indicated in first update : (from the doc)
    Instance. To create a database at another (remote) database partition server, you must first attach to that server. A database connection is temporarily established by this command during processing.
    that is what you get, when people ask question with very little,encrypted description of problem...
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

  13. #13
    Join Date
    Sep 2012
    Posts
    16
    I have used the command db2attach but it also gives the authority to the all non db2 user(who have not installed the user) so i need a db2 command which returns the username with whom profile has been created while installed the db2.

  14. #14
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    same answer over here : what is the need ?? what is the question ? what is the purpose ??
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

  15. #15
    Join Date
    Sep 2012
    Posts
    16
    O i think it become complex, I don't want to depend on the log as it can be delete by user... can i have not get a command that returns the username with which db2 copy has the login profile.

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
  •