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 > DB2 7.1 and JDBC getColumnName()

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-30-03, 01:40
A340-313X A340-313X is offline
Registered User
 
Join Date: Aug 2003
Posts: 11
DB2 7.1 and JDBC getColumnName()

Hello all

I am using a Windows 2000 workstation and DB/2 Admin Client 7.2 FP10. The remote DB/2 server is running DB/2 UDB 7.1 FP4 or FP5 on Windows 2000 as well.

I have a Java program that connects to the database using the com.ibm.db2.jdbc.app.DB2Driver driver. However, neither ResultSetMetaData.getColumnName() nor DatabaseMetaData.getColumns() seem to be working for me. They all return empty values.

Does anybody know of a workaround over this problem? (Like maybe using some custom DB/2 command or something to be passed through Java?)

Would appreciate any help I can get. Thanks!
Reply With Quote
  #2 (permalink)  
Old 10-30-03, 09:18
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Re: DB2 7.1 and JDBC getColumnName()

Quote:
Originally posted by A340-313X

I have a Java program that connects to the database using the com.ibm.db2.jdbc.app.DB2Driver driver. However, neither ResultSetMetaData.getColumnName() nor DatabaseMetaData.getColumns() seem to be working for me. They all return empty values.

Can you give us an example of your query? I believe if a result set column is a function or some other computed value then getColumnName() will not return anything, since this wouldn't be a cataloged name.

Try assigning a label to that column and use getColumnLabel() to retrieve it.

Hope this helps.

Nick
Reply With Quote
  #3 (permalink)  
Old 10-30-03, 19:18
A340-313X A340-313X is offline
Registered User
 
Join Date: Aug 2003
Posts: 11
Thanks for your reply Nick!

I believe I have found a way around this through some research on the Internet. The query I'm executing is a simple SELECT * query so it shouldn't be a function of computed values. In any case, in order to obtain the column names, one could try:

SELECT TABNAME, TABSCHEMA, COLNAME, COLNO
FROM SYSCAT.COLUMNS
WHERE TABNAME IN ('tablename') AND TABSCHEMA IN ('schema')
ORDER BY COLNO ASC

Hope this helps!
Reply With Quote
  #4 (permalink)  
Old 10-31-03, 09:27
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally posted by A340-313X
research on the Internet. The query I'm executing is a simple SELECT * query so it shouldn't be a function of computed
Here you go! To get column names you'll have to have an explicit select list, like

SELECT FIELD1, FIELD2, YEAR(FIELD3) AS YEAR FROM....
Reply With Quote
Reply

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