0

SQLJet を Java プロジェクトの SQLite ライブラリとして使用して、テーブルのインデックスを作成し、それを使用してデータベースから何かを取得すると、エラーが発生し続け、何が間違っているのかわかりません。コードを少し言い換えました (複数のテーブルを作成しましたが、意味はありません)。このエラーを修正するにはどうすればよいですか?

org.tmatesoft.sqljet.core.SqlJetException: Index not exists: FULL_NAME_INDEX: error code is MISUSE
    at org.tmatesoft.sqljet.core.internal.table.SqlJetTable.checkIndexName(SqlJetTable.java:285)
    at org.tmatesoft.sqljet.core.internal.table.SqlJetTable.access$300(SqlJetTable.java:46)
    at org.tmatesoft.sqljet.core.internal.table.SqlJetTable$2.runWithLock(SqlJetTable.java:149)
    at org.tmatesoft.sqljet.core.table.SqlJetDb$1.runSynchronized(SqlJetDb.java:172)
    at org.tmatesoft.sqljet.core.table.engine.SqlJetEngine.runSynchronized(SqlJetEngine.java:217)
    at org.tmatesoft.sqljet.core.table.SqlJetDb.runWithLock(SqlJetDb.java:170)
    at org.tmatesoft.sqljet.core.internal.table.SqlJetTable.lookup(SqlJetTable.java:146)
    at eureqapp.DatabaseManager.getContact(DatabaseManager.java:408)

私のコード:

public DatabaseManager() throws SqlJetException, IOException
{
    try
    {
        //Creates a database file, if it doesn't exist already.
        File dbFile = new File(databaseFileName);
        if (!dbFile.exists())
        {
            dbFile.createNewFile();

            db = SqlJetDb.open(dbFile, true);
            db.beginTransaction(SqlJetTransactionMode.WRITE);
            db.getOptions().setUserVersion(1);
            createTables();

        } else
        {
            db = SqlJetDb.open(dbFile, true);
            db.beginTransaction(SqlJetTransactionMode.WRITE);
            db.getOptions().setUserVersion(1);
        }
    } catch (Exception e)
    {
        e.printStackTrace();
    } finally
    {

        if (db.isOpen())
        {
            db.commit();
            db.close();
        }
    }
}

public static void createTables() throws SqlJetException
{
    try
    {
        if (!db.isOpen())
        {
            db.open();
        }

        db.beginTransaction(SqlJetTransactionMode.WRITE);
        db.createTable(CREATE_TABLE_CONTACT);
        db.createIndex(CREATE_CONTACT_NAME_INDEX);



    } catch (Exception e)
    {
        e.printStackTrace();
    } finally
    {

        if (db.isOpen())
        {
            db.commit();
            db.close();
        }
    }
}

getContact メソッドを呼び出す場所

public static Contact getContact(String name) throws SqlJetException
{
    Contact c = new Contact();

    try
    {
        if (!db.isOpen())
        {
            db.open();
        }
        db.beginTransaction(SqlJetTransactionMode.READ_ONLY);

        ISqlJetTable table = db.getTable("CONTACT");
        ISqlJetCursor cursor = table.lookup("FULL_NAME_INDEX", name);

        String contactName = cursor.getString("name");
        String contactAddress = cursor.getString("address");
        String contactPlace = cursor.getString("place");
        String contactDepartment = cursor.getString("department");
        String contactTelephone = cursor.getString("telephone_number");
        String contactMobile = cursor.getString("mobile_number");
        String contactEmail = cursor.getString("email_address");
        cursor.close();
        db.close();

        c = new Contact(contactName, contactAddress, contactPlace, contactDepartment, contactTelephone, contactMobile, contactEmail);

        return c;
    } catch (Exception e)
    {
        e.printStackTrace();
    }
    return null;
}
4

1 に答える 1

0

インデックスを作成したのと同じユーザーを使用しますか、それともアプリケーションの別のユーザーを使用しますか?
別のユーザーを使用すると、そのユーザーにはインデックスにアクセスして使用する権限がないように見えます。次に、アプリケーション ユーザーがインデックスを使用できるようにします。

于 2012-11-26T09:55:24.077 に答える