我正在使用Java和SQLiteJDBC来使用SQLite。我需要访问给定表的列名,并且我发现可以通过以下命令来完成这一任务:
pragma table_info(myTable)但是,在尝试执行以下操作时,我会得到一个错误。
PreparedStatement _pstmt =
this._DBConnection.prepareStatement("pragma table_info( '?' );",
new String[] {_tableName} );java.sql.SQLException: NYI
我不知道NYI是什么意思,而且,我也不确定我是否能做我想做的事情。关于如何获得列名,有什么建议吗?
发布于 2009-08-28 02:14:28
NYI的意思是“尚未实施”。
我猜想命令“杂注table_info”可能不能作为预先准备好的语句直接执行。
在SQLite JDBC驱动程序、类org.sqlite.Metadata、方法(如getColumns()和getPrimaryKeys() )的代码中,有一个执行该杂注语句的示例。
我不能摘录代码并在这里发布,因为这样做与StackOverflow使用的不兼容。所以请到那个链接去看看。
发布于 2009-08-28 02:20:19
这是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表中获取实际的列定义,并自己解析它们。
https://stackoverflow.com/questions/1344599
复制相似问题