在Statement准备中的Sqlite pendingOperation

时间:2012-03-30 10:42:00

标签: sqlite blackberry java-me

我的代码是:

Statement mstatement = null;
URI uri = URI.create(DBPath);
sqliteDb = DatabaseFactory.openOrCreate(uri);

mStatement = sqliteDb.createStatement(strQuery);
mStatement.prepare();

我的问题是,我在mstatement.prepare();收到“Sqlite pendingOperation”错误。 我在每个数据库处理方法中使用synchronized块。当多个线程正在运行时会发生这种情况。

1 个答案:

答案 0 :(得分:2)

我自己得到了答案。

我将所有方法修改为(粗体):

Cursor c = null;
DBHelper.mStatement = null;
Vector followups = new Vector();
**boolean runFlag = true;**
synchronized (GlobalVariables.lockObject) {
try {
**while(runFlag)**
SELECT EventId,OldTitle,OrderNumber,Status,Title,Type,UpdateDateTime,Id FROM Questions WHERE EventId=5 AND Type=1 AND (Status=0 OR Status=1 OR Status=2) ORDER BY OrderNumber 

                DBHelper.CreateAndOpenSqliteDBConnection();
DBHelper.mStatement = DBHelper.sqliteDb.createStatement(strQuery);
DBHelper.mStatement.prepare();

**if(DBHelper.mStatement == null)
    {
        DBHelper.CloseSqliteDBConnection();
                        runFlag = true;
                        continue;
                    }
                    else
                    {
                        runFlag = false;
                    }**

c = DBHelper.mStatement.getCursor();

while (c.next()) {
                    followups.addElement(Followup.getFromCursor(c));
                }
}
**}**
catch (Exception ex) {
System.out.print(ERRORSTRING + "getUploadFollowupsFromDB: "
                        + ex);
} finally {

DBHelper.CloseSqliteDBConnection();
}
GlobalVariables.lockObject.notifyAll();
}
return followups;

Great Ankit Rox ..