문제

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

다른 팁

In MySQL the comment associated with each table is available from the information_schema.

Try this query:

 SELECT TABLE_NAME, TABLE_COMMENT
   FROM INFORMATION_SCHEMA.TABLES
  WHERE TABLE_SCHEMA = 'YourDatabaseName'

Be sure to substitute the data base name you're actually using.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top