夏天留念
夏天留念
  • 发布:2025-10-28 10:36
  • 更新:2025-11-07 15:01
  • 阅读:153

请教高手:APP一直打开sqlite失败,提示1403错误,该怎么解决?路径填写是对的

分类:uni-app

大家好,

我要在安装APP的设备上使用自带的单机sqlite数据库,我使用uniapp的sqlite插件,在调用打开数据库的时候报这样的错:openDatabase failed: {"code":-1403,"message":"Cannot create file private directory,such as:'www',https://ask.dcloud.net.cn/article/282"},我没有看明白,这个是报错提示是私有目录,我就是按网上说的在根目录下建立_doc目录,然后把数据库放到里面,不知道哪里错了,请高手帮忙看看,感谢了

这个是连接代码:
function openDB(){
console.log("plus.io.PRIVATE_DOC:"+plus.io.PRIVATE_DOC);
plus.sqlite.openDatabase({
name: 'db',
path: '../../_doc/db.db',
success: function(e){
console.log('openDatabase success!');
plus.sqlite.executeSql({
name: 'measure',
sql: 'select * from measure where is_default = 1',
success: function(e){
console.log('返回数据:'+JSON.stringify(e));
},
fail: function(e){
console.log('executeSql failed: '+JSON.stringify(e));
}
});

    },  
    fail: function(e){  
        console.log('openDatabase failed: '+JSON.stringify(e));  
    }  
});  

}

目录层级是:
./_doc/db.db
./pages/index/index.vue

程序在index.vue里,使用vue3

2025-10-28 10:36 负责人:无 分享
已邀请:
夏天留念

夏天留念 (作者)

请问有人知道吗?在线等待高手

蔡cai

蔡cai - 开发的插件:https://ask.dcloud.net.cn/article/41539

  • 夏天留念 (作者)

    谢谢您的回复,这个文档我又看,但是我不理解他的意思。


    我现在就是不知道这个path究竟该怎么写,我已经有做好的sqlite数据库,请问我应该放到项目根目录的哪个位置?怎么调用?


    现在程序目录层级是:

    ./_doc/db.db

    ./pages/index/index.vue

    我的程序是index.vue,调用sqlite数据库db.db我是这样写的代码:


    plus.sqlite.openDatabase({

    name: 'db',

    path: '../../_doc/db.db',

    success: function(e){

    console.log('openDatabase success!');

    }

    ......

    我这样写,调试提醒错误openDatabase failed: {"code":-1403,"message":"Cannot create file private directory,such as:'www',https://ask.dcloud.net.cn/article/282"},但是我并没有放到www目录下,我不知道是哪里错了,请帮忙看下,感谢了!

    2025-11-06 11:27

  • 蔡cai

    回复 夏天留念: 像他的例子,path: '_doc/test.db',

    2025-11-06 11:34

  • 蔡cai

    ../../_doc/db.db改为_doc/db.db试试

    2025-11-06 11:35

  • 夏天留念 (作者)

    回复 蔡cai: 谢谢回复,我的index.vue 和 test.db不是同一级别的,也这么写吗?相对路径差了2层。另外 _doc这个是一个目录,还是下划线关键词+doc ?

    2025-11-06 11:36

  • 蔡cai

    回复 夏天留念: 一个目录吧,我也没试过,按照我的理解就是在你手机里,当前应用的文件夹下创建一个这个目录

    2025-11-06 11:41

  • 蔡cai

    回复 蔡cai: 像安卓手机就是在文件管理的手机存储里面

    2025-11-06 11:44

  • 夏天留念 (作者)

    回复 蔡cai:我刚试了下,错误改变了,变成打开数据库但是找不到数据表的错误

    executeSql failed: {"code":-1404,"message":"android.database.sqlite.SQLiteException: no such table: measure (code 1 SQLITE_ERROR): , while compiling: select * from measure where is_default = 1,https://ask.dcloud.net.cn/article/282"} at pages/index/index.vue:218


    但是我非常确认,数据库里有这个表,不可能错。

    不知道是哪里问题

    2025-11-06 11:55

  • 夏天留念 (作者)

    以下是查询语句:

    plus.sqlite.executeSql({

    name: 'measure',

    sql: 'select * from measure where is_default = 1',

    success: function(e){

    console.log('返回数据:'+JSON.stringify(e));

    },

    fail: function(e){

    console.log('executeSql failed: '+JSON.stringify(e));

    }

    });

    2025-11-06 11:57

  • 蔡cai

    回复 夏天留念: 那你调用plus.sqlite.openDatabase和plus.sqlite.executeSql的name都不一致

    2025-11-06 12:05

  • 夏天留念 (作者)

    回复 蔡cai: 后面实际的name已经修改过,都是measure,但是还是提示上面错误

    2025-11-06 13:11

  • 蔡cai

    回复 夏天留念: 那你代码贴出来看看吧

    2025-11-06 13:35

  • 夏天留念 (作者)

    回复 蔡cai:


    function openDB(){

    console.log('openDB start: ');

    plus.sqlite.openDatabase({

    name: 'measure',

    path: '_doc/tt.db',

    success: function(e){

    console.log("发现文件!"+JSON.stringify(e));


            plus.sqlite.executeSql({  
    name: 'measure',
    sql: 'select * from measure where is_default = 1',
    success: function(e){
    console.log('返回数据:'+JSON.stringify(e));
    },
    fail: function(e){
    console.log('executeSql failed: '+JSON.stringify(e));
    }
    });

    },
    fail: function(e){
    console.log("未发现文件,请检查!"+JSON.stringify(e));
    }
    });

    }

    代码如上:

    我尝试修改数据库名称,再测试,还是提示这个错误:


    15:08:03.469 executeSql failed: {"code":-1404,"message":"android.database.sqlite.SQLiteException: no such table: measure (code 1 SQLITE_ERROR): , while compiling: select * from measure where is_default = 1,https://ask.dcloud.net.cn/article/282"} at pages/index/index.vue:218

    2025-11-06 15:10

  • 夏天留念 (作者)

    把db.db修改成tt.db测试

    2025-11-06 15:11

  • 夏天留念 (作者)

    回复 蔡cai: 我查了手机内存,发现是程序自行建立了db.db, 里面没有我创建的measure表。难道是不能使用自己创建的db数据库吗?

    2025-11-06 15:29

  • 蔡cai

    回复 夏天留念: 没试过

    2025-11-06 15:38

  • 蔡cai

    回复 夏天留念: 看有没有大佬这样子弄

    2025-11-06 15:40

  • 夏天留念 (作者)

    回复 蔡cai: 多谢回复!

    2025-11-06 15:44

  • 蔡cai

    回复 夏天留念: 或者你去搜索、问下ai啥的,看有没有

    2025-11-06 16:00

  • 蔡cai

    回复 夏天留念: 客气

    2025-11-06 16:00

  • 夏天留念 (作者)

    回复 蔡cai: 试过了,还没调出来。AI给的有的能用,有的不行。我写的代码也是参考AI和官方文档写的。

    2025-11-06 18:30

  • 蔡cai

    回复 夏天留念: 行吧

    2025-11-07 09:11

夏天留念

夏天留念 (作者)

文档里说的 _doc/a.db 的 "doc" 究竟是一个文件夹,还是说 “” 关键词 + “doc”文件夹?文档说的很模糊,让人很疑惑

  • 夏天留念 (作者)

    doc前面的下划线被屏蔽了,显示不出来

    2025-11-06 11:34

蔡cai

蔡cai - 开发的插件:https://ask.dcloud.net.cn/article/41539

  • 夏天留念 (作者)

    谢谢回复,我在项目根目录下面创建了./_doc/db.db 我要使用已经建好的数据库,不是要新建数据库。

    2025-11-06 15:13

夏天留念

夏天留念 (作者)

请问官方能否帮忙看看,谢谢了!

要回复问题请先登录注册