Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2011
    Posts
    9

    Answered: Validate the DB2 command's output on Japenese/Chinese machine

    The application works fine on Windows machines where DB2 is setup in English language, since need to validate the executed commands output like

    > db2 attach to DB2 user db2admin using xxxxxx

    Instance Attachment Information

    Instance server = DB2/NT64 10.5.1
    Authorization ID = DB2ADMIN
    Local instance alias = DB2

    Actually the above output is redirected into a text file and then validated by a Java code as

    String message = Utils.readFile(filePath);
    message = message.trim().replaceAll("\\s+", " ");
    String upperStr = message.toUpperCase();

    if (upperStr.indexOf("INSTANCE ATTACHMENT INFORMATION") != -1
    && upperStr.indexOf("AUTHORIZATION ID") != -1)
    return "SUCCESS";
    else
    return "FAILURE";

    But the issue is: On Japanese/Chinese machine the DB2 commands generate the output in their language e.g. In Japanese Machine

    インスタンス?Eアタッチ?﨣・インスタンス?Eサ?[バ?[ = DB2/NT 10.5.5 許可 ID = DB2ADMIN ・?[カル?Eインスタンス別名 = DB2



    So, how to modify that language to work normally like English?
    Or could the command's output be generated in English only?

    Thanks In Advance!!!

  2. Best Answer
    Posted by mark.b

    "Hi,

    Try to run the following bat file db2_test_rc.bat and show us the result.

    db2 attach to db2 user foo using bar
    set rc=%ERRORLEVEL%
    echo %rc%

    db2 attach to db2
    set rc=%ERRORLEVEL%
    echo %rc%
    "


  3. #2
    Join Date
    Apr 2012
    Posts
    1,035
    Provided Answers: 18
    DB2 CLP will report its output message according to the regional-settings on the machine and according to which languages its binaries are supplied with. This determines not only the language used for displayed messages but also determines other things like the decimal-point, the display format of money or time etc. So you don't want to change that.

    It is an bad and incorrect design to parse output and expect it to be always in English. If the objective is to test whether the ATTACH action completed then one correct action would be to test the return-code from the ATTACH , zero means success. That is language and locale independent.

  4. #3
    Join Date
    Mar 2011
    Posts
    9
    Thanks db2mor, but in that case, I need to handle all the return-codes of ATTACH command?


    And when ATTACH command runs successfully, it doesn't return the message containing ZERO. So do you suggest me how to handle that way??


  5. #4
    Join Date
    Apr 2012
    Posts
    1,035
    Provided Answers: 18
    If you are submitting the ATTACH via CLP, then all CLP commands have the same return-code pattern ( 0 = success, 1=no rows found, 2=warning, >3 means error). You normally are concerned with success (exit code 0 from CLP) or error (exit code higher than 3). This assumes you understand what a return-code is. Notice that these are not sqlcodes or sqlstates, they are exit codes for any CLP command, and this is clearly documented in the IBM DB2 knowledge center.

  6. #5
    Join Date
    Mar 2011
    Posts
    9

    Question

    I tried to get the
    Code:
    Process.exitValue()
    by supplying the incorrect username & password in ATTACH command

    Code:
    db2 attach to DB2 user db2admin2 using xxxxxx
    but still I am getting the ZERO = 0 as the return value.

    So in that case how to rely on the returnCode??

  7. #6
    Join Date
    Apr 2012
    Posts
    1,035
    Provided Answers: 18
    Your present issue is with java, not with DB2. You have to arrange to use a java method that guarantees to return the real exit code from the DB2 CLP to the java program for testing. That is not a matter for DB2, it is a matter for your java programming skills.

  8. #7
    Join Date
    Mar 2011
    Posts
    9
    Yes, you are absolutely correct.

    But Is there any way to get the CLP return value by Java code or something else. Since on running the ATTACH command with incorrect credential it simply returns the ERROR code, not the return-code as you said

    > db2 attach to DB2 user db2admin2 using xxxxxxx
    SQL30082N Security processing failed with reason "24" ("USERNAME AND/OR PASSWORD INVALID"). SQLSTATE=08001

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

    Try to run the following bat file db2_test_rc.bat and show us the result.

    db2 attach to db2 user foo using bar
    set rc=%ERRORLEVEL%
    echo %rc%

    db2 attach to db2
    set rc=%ERRORLEVEL%
    echo %rc%
    Regards,
    Mark.

  10. #9
    Join Date
    Apr 2012
    Posts
    1,035
    Provided Answers: 18
    You need to ask that question on a java forum (not a DB2 forum). Be aware also that there is 'C' language API binding called sqleatin which performs an instance-attachment. You might be able to have an java method for invoking that. Refer to the DB2 information centre for details of that API. Otherwise don't expect java advice in a DB2 forum.

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
  •