Blackberry デバイス用のアプリを開発しています。このアプリにはデータベースが含まれています。API は最新の API バージョンで提供されているため、SQLite を使用することにしました。
どこでも見つけることができるすべてのサンプルに従いましたが、何が起こっても、データベースは空のままで、「DatabaseIOException : File system error (12)」が発生します。
私は現在シミュレーターに取り組んでいることを付け加えておきます。
関連するコードは次のとおりです。
// Creation of the database
private static final String DATABASE_NAME = "myDatabase.db";
private static final String STORAGE_LOCATION = "/store/databases/myApp/";
try
{
// Create URI
URI uri = URI.create(STORAGE_LOCATION + DATABASE_NAME);
// Open or create a plain text database. This will create the
// directory and file defined by the URI (if they do not already exist).
db = DatabaseFactory.openOrCreate(uri, new DatabaseSecurityOptions(false));
// Close the database in case it is blank and we need to write to the file
db.close();
this.CreateTable();
}
catch ( Exception e )
{
System.out.println( e.getMessage() );
e.printStackTrace();
}
テーブル作成方法:
public void CreateTable(){
URI uri;
try {
uri = URI.create(STORAGE_LOCATION + DATABASE_NAME);
// Create a new DatabaseOptions object forcing foreign key constraints
DatabaseOptions databaseOptions = new DatabaseOptions();
databaseOptions.set( "foreign_key_constraints", "on" );
// Open the database
db = DatabaseFactory.open(uri, databaseOptions);
} catch (ControlledAccessException e) {
e.printStackTrace();
} catch (DatabaseIOException e) {
e.printStackTrace();
} catch (DatabasePathException e) {
e.printStackTrace();
} catch (IllegalArgumentException e1) {
e1.printStackTrace();
} catch (MalformedURIException e1) {
e1.printStackTrace();
} catch (DatabaseOptionsSetInvalidKeyException e) {
e.printStackTrace();
} catch (DatabaseOptionsSetInvalidValueException e) {
e.printStackTrace();
}
Statement st;
try {
st = this.getDb().createStatement("CREATE TABLE '" + TABLE_NAME1 +
"'('id' PRIMARY KEY, 'libContexte' TEXT, 'libelle' TEXT, 'xcoord' REAL, "+
"'ycoord' REAL)");
st.prepare();
st.execute();
} catch (DatabaseException e) {
e.printStackTrace();
}
try {
db.close();
} catch (DatabaseIOException e) {
e.printStackTrace();
}
}
助けてくれてありがとう、私は本当に問題がどこから来ているのかわかりません。