getting column names

I'm trying to write some java code that requires dynamically knowing the names of the columns of a table.

Is there a way to fetch the column names of a table? Either through a query or just be saying "get column names" ? I'd get them and then populate the column names into an array.

Thanks

ps - if it makes a difference, the database I'm programming against is MySQL

[395 byte] By [--Sweet--a] at [2007-10-3 3:39:18]
# 1

> Is there a way to fetch the column names of a table?

> Either through a query or just be saying "get column

> names" ? I'd get them and then populate the column

> names into an array.

Here's a way I did it. Might not be the best way but it works.

private static Object[] createColumnNameArray(ResultSet rs)

throws SQLException{

int col = 0;

col = getColumnCount(rs);

String columnLabel = null;

Object[] columnNames = new Object[col];

ResultSetMetaData rsmd = null;

rsmd = rs.getMetaData();

for (int i = 0; i < col; i++){

columnNames[i] = rsmd.getColumnLabel(i+1);

}

return columnNames;

}

thanks.

mp

pdxlooiea at 2007-7-14 21:34:45 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...