Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ResultMetaData getColumnName does not work

Status
Not open for further replies.

SilverStray

Programmer
Oct 25, 2001
47
AU
Hi,

The JAVA API states that getColumnLabel() function of object ResultMetaData can be used to use the display label of the SQL resultset, while the getColumnName() function is used to get the column name as specified in the table.

I used getColumnName() to get the exact column name as defined in the table, but it doesn't seem to work. It picks up the label name just like the value picked up by getColumnLabel().

PreparedStatement ps = conn.prepareStatement(sqlStmt);
ResultSet rs = null;
rs = ps.executeQuery();
ResultSetMetaData rsmd = rs.getMetaData();

for (int i = 1; i <= numberOfColumns; i++) {
System.out.println(rsmd.getColumnName(i));
}

Please help! Thanks!
 
I think you have to remember that JDBC drivers are implementations of the java.sql API - so each driver could be differerent.

I expect that your driver's getColumnName() and getColumnLabel() are just coded to return the same thing.

For example, here is the source code from the MySQL driver; as you can see, getColumnLabel() just calls getColumnName().

Code:
    /**
     * What is the suggested column title for use in printouts and
     * displays?
     *
     * @param column the first column is 1, the second is 2, etc.
     * @return the column label
     * @throws java.sql.SQLException if a database access error occurs
     */
    public String getColumnLabel(int column) throws java.sql.SQLException {
        return getColumnName(column);
    }

    /**
     * What's a column's name?
     *
     * @param column the first column is 1, the second is 2, etc.
     * @return the column name
     * @throws java.sql.SQLException if a databvase access error occurs
     */
    public String getColumnName(int column) throws java.sql.SQLException {
        return getField(column).getName();
    }

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top