Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2003
    Posts
    11

    Unanswered: 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!

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1

    Re: DB2 7.1 and JDBC getColumnName()

    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
    ---
    "It does not work" is not a valid problem statement.

  3. #3
    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!

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    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....
    ---
    "It does not work" is not a valid problem statement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •