MySQL Forums
Forum List  »  Newbie

Re: How can I return column-name?
Posted by: Roland Bouman
Date: July 22, 2005 03:30AM

Well, you could take an approach similar to Chris Stubben's, (maybe include a LIMIT clause ).
Of course, when you decide to grab column names yourself you could use any statement you think's suitable to do it (SHOW CREATE TABLE ex.)

Alternatively, you could also try to make a connection using some driver that supports metadata and hope it does the job for you.
For example, make a jdbc connection and use the DatabaseMetaData object:

import java.sql.*;

Connection conn;

//init connection
..
DatabaseMetaData md = conn.getMetaData();
ResultSet rs = md.getColumns("","mydatabase","mytablename","%");
//traverse the resultset
while (rs.next()){
System.out.println(rs.getString("COLUMN_NAME"));
}

see http://java.sun.com/j2se/1.5.0/docs/api/java/sql/DatabaseMetaData.html

The ODBC interface also provides metadata in this manner

Options: ReplyQuote


Subject
Written By
Posted
Re: How can I return column-name?
July 22, 2005 03:30AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.