2009-08-28 72 views
4

我正在利用Java和SQLiteJDBC來使用SQLite。我需要給定表訪問列的名稱,我發現我可以用下面的命令做到這一點:SQLiteJDBC和PreparedStatement使用編譯指南table_info

pragma table_info(myTable) 

但是,試圖做到以下幾點,當我得到一個錯誤。

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

值java.sql.SQLException:NYI

我不知道是什麼意思NYI,此外,我不知道如果我可以做我想要做的事。關於如何完成獲取列名的任何建議?

回答

3

NYI意味着「尚未實施」。

我猜想命令「pragma table_info」可能無法直接作爲預處理語句執行。

有一個在SQLite JDBC驅動程序的代碼中執行該編譯指示語句的示例,類org.sqlite.Metadata,方法如getColumns()getPrimaryKeys()

我不能摘抄的代碼,並張貼在這裏,因爲這樣做會不會與StackOverflow上使用Creative Commons許可兼容。所以請轉到該鏈接並看看。

+0

我看着代碼,我看到你在說什麼。謝謝。 – 2009-08-28 15:35:50

2

有此摘錄的代碼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); 
    } 

我猜紐約攝影學院的意思是「尚未實現。」。

如果編譯的是不工作了,

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表搶實際列定義和分析出來自己。