我的 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;
}