SQLiteJDBC 和PreparedStatement 使用pragma table_info
-
20-09-2019 - |
题
我正在使用 Java 和 SQLiteJDBC 使用 SQLite。我需要访问给定表的列名,我发现可以使用以下命令来完成此操作:
pragma table_info(myTable)
但是,当尝试执行以下操作时,我收到错误。
PreparedStatement _pstmt =
this._DBConnection.prepareStatement("pragma table_info( '?' );",
new String[] {_tableName} );
java.sql.SQLException:纽约州
我不知道 NYI 是什么意思,而且,我不确定我是否能做我想做的事。关于如何完成获取列名称有什么建议吗?
解决方案
NYI 的意思是“尚未实施”。
我猜想命令“pragma table_info”可能无法直接作为准备好的语句执行。
有一个在 SQLite JDBC 驱动程序类的代码中执行该 pragma 语句的示例 org.sqlite.元数据, ,方法如 getColumns()
和 getPrimaryKeys()
.
我无法摘录代码并将其发布到此处,因为这样做与 StackOverflow 使用的知识共享许可证不兼容。因此,请访问该链接并查看。
其他提示
有此摘录的代码从 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是指 “尚未实施。”
如果在pragma事情是不工作的,
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
表抢实际列定义和分析出来自己。
不隶属于 StackOverflow