jdbc 获取mysql表注解,使用DatabaseMetaData检索mysql表注释 | 您所在的位置:网站首页 › jdbc获取表注释 › jdbc 获取mysql表注解,使用DatabaseMetaData检索mysql表注释 |
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 getTableNames(DatabaseMetaData md) throws SQLException { ArrayList tables = new ArrayList(); 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. |
CopyRight 2018-2019 实验室设备网 版权所有 |