2

I am doing a project and I need to find some information of any given table of mysql. I need names of columns and their attributes such if any of them is index or not. I'm doing this in Java, how can I get this piece of info about any table?

thanks

Mossen
  • 484
  • 4
  • 16

2 Answers2

1

Using JDBC, you can get that with:

String tableNamePattern = "customer";
DatabaseMetaData databaseMetaData = conn.getMetaData();

ResultSet columns = 
       databaseMetaData.getColumns(null, null, tableNamePattern, null);

ResultSet primaryKeys = 
       databaseMetaData.getPrimaryKeys(null, null, tableNamePattern);

ResultSet indexInfo = 
       databaseMetaData.getIndexInfo(null, null, tableNamePattern, false, false);

You can see the information, e.g. using Most simple code to populate JTable from ResultSet.

Community
  • 1
  • 1
Paul Vargas
  • 40,346
  • 15
  • 98
  • 144
0

I think it's good as an example: http://www.herongyang.com/JDBC/sqljdbc-jar-Column-List.html

Mossen
  • 484
  • 4
  • 16