Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve mysql table comment using DatabaseMetaData

So I'm using Vaadin Java web framework for a project which requires the ability to edit the table. Vaadin provides a way to get Connection object from SimpleJDBCConnectionPool (Here's the API)

From the Connection I can get DatabaseMetaData object. And I have the following code:

private List<String> getTableNames(DatabaseMetaData md) throws SQLException {
        ArrayList<String> tables = new ArrayList<String>();
        ResultSet rs = md.getTables(null, null, "", null);
        while (rs.next()) {
            tables.add(rs.getString("TABLE_NAME")); //Column 3 is for table name
            Logger.getLogger(CodeContainingClass.class.getName()).
                    info("Comment: " + rs.getString("REMARKS")); //Column 5 is for remarks
        }
        return tables;
}

It retrieves the Table name correctly, but unfortunately the REMARKS returns null. (Here's the API). I'm not sure what I'm doing wrong.

I verified that the table has a comment using the following query:

SHOW TABLE STATUS WHERE Name='tablename';

Any help will be greatly appreciated. Thank you very much.

like image 257
Monir Avatar asked Mar 17 '26 04:03

Monir


1 Answers

See this MySQL Connector/J bug (specifically the comment at 27 Jun 2012 11:26 and 28 Jun 2012 11:18). You need to specify connection property useInformationSchema=true to get this functionality.

See also the Connector/J Connection properties

like image 171
Mark Rotteveel Avatar answered Mar 19 '26 18:03

Mark Rotteveel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!