使用DatabaseMetaData检索mysql表注释 [英] Retrieve mysql table comment using DatabaseMetaData

查看:1188
本文介绍了使用DatabaseMetaData检索mysql表注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在使用Vaadin Java Web框架来完成一个需要编辑表的项目。 Vaadin提供了一种从 SimpleJDBCConnectionPool 获取 Connection 对象的方法(这是API

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)

来自连接我可以获得 DatabaseMetaData 对象。我有以下代码:

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;
}

它正确检索表名,但不幸的是REMARKS返回。 (这是API 。我不确定我做错了什么。

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.

推荐答案

请参阅 MySQL Connector / J bug (特别是2012年6月27日11:26和2012年6月28日11:18的评论)。您需要指定连接属性 useInformationSchema = true 才能获得此功能。

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.

另请参阅连接器/ J连接属性

这篇关于使用DatabaseMetaData检索mysql表注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆