1

データベース画面に初めて入るときに表示されるタブバーを作成しました。このコードは正常に機能しています。しかし、別のタブに移動してから再びデータベース画面のタブに移動すると、例外がスローされます

net.rim.device.api.database.DatabaseIOException: ファイル システム エラー (12)

データベースを適切に閉じました。

最終ブロックでデータベースを閉じました。タブを移動するたびにデータベースが閉じています

これは私のコードです:

    Database d = null;
    URI _uri = null;
    Statement st = null;
    Cursor c = null;

    try
    {

         _uri=URI.create("file:///SDCard/MyBudgetTracker.db");
            if (DatabaseFactory.exists(_uri)) {
                d=DatabaseFactory.openOrCreate(_uri,new DatabaseSecurityOptions(false));
                 st = d.createStatement("SELECT * FROM "+Globalvalue.planCategoryTable);
                st.prepare();
                 c = st.getCursor();
                Row r;
                int i = 0;

                while(c.next()) {
                    r = c.getRow();
                    r.getString(0);
                    i++;
                }
                if (i==0)
                {
                    add(new RichTextField("No data in the User table."));
                }

        }


    }catch (Exception e) 
    {
        System.out.println(e.getMessage());
        System.out.println(e);
        e.printStackTrace();// TODO: handle exception
    } finally {
        try {
            if (DatabaseFactory.exists(_uri)) {
                if (c != null) {
                    c.close();
                }if (st != null) {
                    st.close();
                } if (d != null) {
                    d.close();
                }
            }
        } catch (Exception e2) {
            // TODO: handle exception
        }
    }
4

1 に答える 1

-1

データベースから選択したタブに値を取得していますか? データベースを開いたり閉じたりするこの代替方法を考えることができます。常にエラーが少なくなります。

try
{    
    //Open or create the database
    Database db = DatabaseFactory.openOrCreate("MyBudgetTracker.db");    
    //Retrieve Data from db
    Statement statement1 = db.createStatement("SELECT * FROM "+Globalvalue.planCategoryTable);
    statement1.prepare();
    statement1.execute();       
    statement1.close(); 
    db.close();
}
catch(DatabaseException dbe)
{
    System.err.println(dbe.toString());
}

それ以外の場合は、値をフェッチする前に、各タブに db open ステートメントを含めることができますが、プログラミング コード行が増加します。

于 2012-04-24T07:22:16.657 に答える