Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2010
    Posts
    7

    Unanswered: Problems with aliases in DB2 9.x X JDBC 4

    Hi,

    Sorry about my english

    When I use the driver JDBC 4 (db2jcc4.jar) for the DB2 9.X and I make a selection with column alias, in the exibition the columns names keep their original names.


    E.g.:

    SELECT c1 as t1 from table1

    c1
    --
    X
    Y
    Z

    does anybody have any idea about this problem?

    thanks in advance

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    This must be your application problem.

    Code:
    C:\Temp>clpplus -nw user/password@localhost:50000/database
    CLPPlus: Version 1.3
    Copyright (c) 2009, IBM CORPORATION.  All rights reserved.
    
    
    Database Connection Information :
    ---------------------------------
    Hostname = localhost
    Database server = DB2/NT  SQL09073
    SQL authorization ID = user
    Local database alias = DATABASE
    Port = 50000
    
    SQL> create table table1(c1 char(1));
    
    DB250000I: The command completed successfully.
    
    SQL> insert into table1 (c1) values ('X'),('Y'),('Z');
    
    DB250000I: The command completed successfully.
    
    SQL> select c1 as t1 from table1;
    
    T1
    --
    X
    Y
    Z
    SQL>
    CLPPlus is a Java application that uses the jcc driver.

  3. #3
    Join Date
    Sep 2010
    Posts
    7

    outras under

    Hi n_i,

    Thank you for your post.

    But, beyond the application I am getting errors in DBVisualizer, too.

    When I set the driver how JDBC 2 (db2jcc.jar), the application works.

    But, when I use the native driver JDBC 4 (db2jcc4.jar) I get this wrong behavior.

  4. #4
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    Quote Originally Posted by diecc View Post
    Hi n_i,

    Thank you for your post.

    But, beyond the application I am getting errors in DBVisualizer, too.

    When I set the driver how JDBC 2 (db2jcc.jar), the application works.

    But, when I use the native driver JDBC 4 (db2jcc4.jar) I get this wrong behavior.
    What do you mean by "native driver"? They are both jdbc drivers (DB2 Type 4), just different versions.

    The db2jcc.jar is NOT the same as the DB2 Type 2 driver.
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

  5. #5
    Join Date
    Sep 2010
    Posts
    7
    Again, sorry about my english.

    I made some mistakes:
    instead of native I meant pure java;
    both drivers are pure java;
    db2jcc.jar is JDBC 3, not JDBC 2.

    When I wrote JDBC 4, I wanted to say specification 4 of JDBC, not JDBC type 4. How in manual:

    "db2jcc.jar and sqlj.zip for 3.0 support"

    "db2jcc4.jar and sqlj4.zip for support of some JDBC 4.0 functions;"

    The specification JDBC 4 has some new functions very interesting, but I dont know how to use the aliases.

    Could it be any servers configuration?

  6. #6
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by diecc View Post
    but I dont know how to use the aliases
    You should use ResultSetMetaData.getColumnLabel() instead of getColumnName()

  7. #7
    Join Date
    Sep 2010
    Posts
    7

    Thanks

    Thanks everybody.

    If the specification JDBC 4 is not compatible with the specification JDBC 3 in relation to this method, then the way is to migrate my projects.

    Thanks one more time.

  8. #8
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    "You can use the useJDBC4ColumnNameAndLabelSemantics property to change this behavior."

    Examples of ResultSetMetaData.getColumnName and ResultSetMetaData.getColumnLabel values - IBM DB2 9.5 for Linux, UNIX, and Windows

  9. #9
    Join Date
    Sep 2010
    Posts
    7

    The solution

    Hi,

    There is a cool property in new specification:

    "For the IBM® Data Server Driver for JDBC and SQLJ version 4.0 and later, the default behavior of ResultSetMetaData.getColumnName and ResultSetMetaData.getColumnLabel differs from the default behavior for earlier JDBC drivers. You can use the useJDBC4ColumnNameAndLabelSemantics property to change this behavior."

    IBM DB2 9.5 Information Center for Linux, UNIX, and Windows

    IBM DB2 9.5 Information Center for Linux, UNIX, and Windows

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
  •