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.
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