0

我的 android 应用程序因此异常而崩溃

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 (?,?,?,?,?,?)

我在代码中的插入语句如下所示

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; 

}
4

2 回答 2

2

插入只是这样做

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

db.insert(TABLE_NAME, null /* nullColumnHack */,
                values);
于 2012-12-02T13:02:55.763 回答
0

看来您的 AttachmentColumns.STATUS 和所有其他字符串都包含“(”。您可以尝试删除它们吗?

于 2012-12-02T13:01:56.720 回答