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
  • 574
  • 5
  • 17

2 Answers2

2

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
  • 41,222
  • 15
  • 102
  • 148
0

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

Mossen
  • 574
  • 5
  • 17