2012-12-02 13 views
0

我的Android應用程序與此異常無法插入值到我的android系統表和sqllite

12-02 12:40:50.145: E/AndroidRuntime(531): Caused by:android.database.sqlite.SQLiteException: near "(": syntax error: , while compiling: insert into target(username, (password, (lastLogin, (numberOfLogins, (status, (endpoint) values (?,?,?,?,?,?) 

代碼我的INSERT語句看起來像這樣

private static final String INSERT = "insert into " + AttachmentTable.TABLE_NAME 
             + " (" + AttachmentColumns.STATUS + ", " 
             + AttachmentColumns.RETRIES + ", " 
             + AttachmentColumns.ATT_URI + ", " 
             + AttachmentColumns.ATT_URI_SOURCE + ", " 
             + AttachmentColumns.COMMENT+ ", " 
             + AttachmentColumns.ADDED + ", " 
             + AttachmentColumns.LAST_RETRY + ", " 
             + AttachmentColumns.FINISHED + ") " + 
             "values (?,?,?,?,?,?,?,?)"; 

在我試圖代碼崩潰保存一個創建的附件。但它不起作用。在Android文件資源管理器中,我可以看到數據庫已創建。這裏保存部分從我的代碼

DataManager data = new DataManagerImpl(this); 
    Attachment att = new Attachment(); 
    att.setAdded("now"); 
    att.setAttUri("test"); 
    att.setAttUriSource("test"); 
    att.setComment("test"); 
    att.setLastRetry("test"); 
    att.setRetries(3); 
    att.setStatus(0); 
    data.setAttachment(att); 

而這裏setAttachment代碼

@Override 
public boolean setAttachment(Attachment t) { 
    boolean retVal = false; 
    try{ 
     db.beginTransaction(); 
     long result = attDao.save(t); 
     if (result != -1) 
      retVal = true; 

    }catch (SQLException e) { 
     Log.e(TAG, "Exception during saving target " + e.getMessage() + " rolling back transaction"); 
    } finally{ 
     db.endTransaction(); 
    } 
    return retVal; 

} 
+0

您的異常發生在* another * insert命令上。檢查調用堆棧中代碼的文件名/行號,然後查看。 –

回答

2

只是插入做到這一點

ContentValues values = new ContentValues(); 
    values.put(AttachmentColumns.STATUS, "hello"); 
    values.put(AttachmentColumns.ATT_URI, "uri"); 
      ... 

db.insert(TABLE_NAME, null /* nullColumnHack */, 
       values); 
0

看來你AttachmentColumns.STATUS和所有其他字符串包含「(」在其中。你可以嘗試將其刪除。

+0

常數沒有「(」在裏面,這就是爲什麼我很困惑,爲什麼它不工作 –