If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Problems with aliases in DB2 9.x X JDBC 4

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-23-10, 11:10
diecc diecc is offline
Registered User
 
Join Date: Sep 2010
Posts: 7
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
Reply With Quote
  #2 (permalink)  
Old 09-23-10, 11:56
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
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.
Reply With Quote
  #3 (permalink)  
Old 09-23-10, 13:26
diecc diecc is offline
Registered User
 
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.
Reply With Quote
  #4 (permalink)  
Old 09-23-10, 16:12
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
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
Reply With Quote
  #5 (permalink)  
Old 09-24-10, 15:29
diecc diecc is offline
Registered User
 
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?
Reply With Quote
  #6 (permalink)  
Old 09-24-10, 15:55
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,407
Quote:
Originally Posted by diecc View Post
but I dont know how to use the aliases
You should use ResultSetMetaData.getColumnLabel() instead of getColumnName()
Reply With Quote
  #7 (permalink)  
Old 09-27-10, 10:01
diecc diecc is offline
Registered User
 
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.
Reply With Quote
  #8 (permalink)  
Old 09-27-10, 10:15
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
"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
Reply With Quote
  #9 (permalink)  
Old 09-27-10, 10:45
diecc diecc is offline
Registered User
 
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
Reply With Quote
Reply

Tags
db2 java

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On