HarmonyOS 鸿蒙Next 使用rdbstore读取已有数据库报错配置已更改

发布于 1周前 作者 eggper 来自 鸿蒙OS

HarmonyOS 鸿蒙Next 使用rdbstore读取已有数据库报错配置已更改

如何查询已有数据库,大佬看一下,下述代码可以创建新数据库,插入、查询表都没问题,但当我放一个已经存在的数据库到沙箱目录下,用这个方法连接数据库失败,报错信息:
cke_5017.png

private context:Context= getContext(this);
private rdbStore:relationalStore.RdbStore|undefined=undefined;
public async getRdb() :Promise<boolean>{
//数据库配置
const STORE_CONFIG: relationalStore.StoreConfig = {
name: RdbProcess.DB_NAME,
securityLevel: relationalStore.SecurityLevel.S3,
};
try{
let store=await relationalStore.getRdbStore(this.context, STORE_CONFIG);
if(store){
this.rdbStore=store;
//创建表
//await this.rdbStore.executeSql(RdbProcess.CREATE_TABLE);
return true;
}else{
return false;
}
}catch (error){
console.error(“创建失败:”+error)
return false;
}
}

let store=await relationalStore.getRdbStore(this.context, STORE_CONFIG);
if(store){
this.rdbStore=store;
//创建表
//await this.rdbStore.executeSql(RdbProcess.CREATE_TABLE);
return true;
}else{
return false;
}
}catch (error){
console.error(“创建失败:”+error)
return false;
}
} //getRdb


更多关于HarmonyOS 鸿蒙Next 使用rdbstore读取已有数据库报错配置已更改的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html

回到顶部