SQLiteJDBC 和PreparedStatement 使用pragma table_info

发布于 2024-08-03 08:50:35 字数 513 浏览 3 评论 0原文

我正在利用 Java 和 SQLiteJDBC 来处理 SQLite。我需要访问给定表的列名,我发现可以使用以下命令来完成此操作:

pragma table_info(myTable)

但是,当尝试执行以下操作时,我收到错误。

PreparedStatement _pstmt =
    this._DBConnection.prepareStatement("pragma table_info( '?' );",
         new String[] {_tableName} );

java.sql.SQLException:NYI

我不知道 NYI 是什么意思,而且,我不确定我是否可以做我想做的事情。关于如何完成获取列名称有什么建议吗?

I'm utilizing Java and SQLiteJDBC to work with SQLite. I need to access name of columns for a given table and I've found that I could accomplish this with the following command:

pragma table_info(myTable)

However, when attempting to do the following I get an error.

PreparedStatement _pstmt =
    this._DBConnection.prepareStatement("pragma table_info( '?' );",
         new String[] {_tableName} );

java.sql.SQLException: NYI

I have no idea what NYI means and furthermore, I'm not sure if I can do what I'm trying to do. Any suggestions on how I can accomplish getting the column names?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤芳又自赏 2024-08-10 08:50:35

NYI 的意思是“尚未实施”。

我猜想命令“pragma table_info”可能无法直接作为准备好的语句执行。

有一个在 SQLite JDBC 驱动程序代码中执行该 pragma 语句的示例,类 org.sqlite.Metadata,诸如 getColumns()getPrimaryKeys() 之类的方法。

我无法摘录代码并将其发布到此处,因为这样做与 StackOverflow 使用的知识共享许可证不兼容。因此,请访问该链接并查看。

NYI means "not yet implemented."

I would guess that the command "pragma table_info" probably can't be executed directly as a prepared statement.

There's an example of executing that pragma statement in the code for the SQLite JDBC driver, class org.sqlite.Metadata, methods such as getColumns() and getPrimaryKeys().

I can't excerpt the code and post it here, because doing so would not be compatible with the Creative Commons license used by StackOverflow. So please go to that link and take a look.

梅倚清风 2024-08-10 08:50:35

下面是 SQLiteJDBC 源代码 的代码摘录:

 public PreparedStatement prepareStatement(String sql, int autoC)
        throws SQLException { throw new SQLException("NYI"); }
    public PreparedStatement prepareStatement(String sql, int[] colInds)
        throws SQLException { throw new SQLException("NYI"); }
    public PreparedStatement prepareStatement(String sql, String[] colNames)
        throws SQLException { throw new SQLException("NYI"); }
    public PreparedStatement prepareStatement(String sql, int rst, int rsc) 
                                throws SQLException {
        return prepareStatement(sql, rst, rsc,
                                ResultSet.CLOSE_CURSORS_AT_COMMIT);
    }

我猜 NYI 的意思是“尚未实施”。

如果编译指示不起作用,

sqlite> CREATE TABLE a(col1, col2, col3);
sqlite> CREATE TABLE b(w, x, y, z);
sqlite> SELECT * FROM sqlite_master;
table|a|a|2|CREATE TABLE a(col1, col2, col3)
table|b|b|3|CREATE TABLE b(w, x, y, z)

sqlite> SELECT sql FROM sqlite_master;
CREATE TABLE a(col1, col2, col3)
CREATE TABLE b(w, x, y, z)

您可以从 sqlite_master 表中获取实际的列定义并自行解析它们。

There's this excerpt of code from SQLiteJDBC source code:

 public PreparedStatement prepareStatement(String sql, int autoC)
        throws SQLException { throw new SQLException("NYI"); }
    public PreparedStatement prepareStatement(String sql, int[] colInds)
        throws SQLException { throw new SQLException("NYI"); }
    public PreparedStatement prepareStatement(String sql, String[] colNames)
        throws SQLException { throw new SQLException("NYI"); }
    public PreparedStatement prepareStatement(String sql, int rst, int rsc) 
                                throws SQLException {
        return prepareStatement(sql, rst, rsc,
                                ResultSet.CLOSE_CURSORS_AT_COMMIT);
    }

I'm guessing NYI means "Not Yet Implemented".

If the pragma thing isn't working out,

sqlite> CREATE TABLE a(col1, col2, col3);
sqlite> CREATE TABLE b(w, x, y, z);
sqlite> SELECT * FROM sqlite_master;
table|a|a|2|CREATE TABLE a(col1, col2, col3)
table|b|b|3|CREATE TABLE b(w, x, y, z)

sqlite> SELECT sql FROM sqlite_master;
CREATE TABLE a(col1, col2, col3)
CREATE TABLE b(w, x, y, z)

You can grab the actual column definitions from the sqlite_master table and parse them out yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文