我的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 (?,?,?,?,?,?)
我在代码中的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 :(得分:2)
插入只需执行此操作
ContentValues values = new ContentValues();
values.put(AttachmentColumns.STATUS, "hello");
values.put(AttachmentColumns.ATT_URI, "uri");
...
和
db.insert(TABLE_NAME, null /* nullColumnHack */,
values);
答案 1 :(得分:0)
您的AttachmentColumns.STATUS和所有其他字符串似乎包含"("在其中。您可以尝试删除它们。