gpt4 book ai didi

java - 如何将一串 base64 编码的数据插入到 sqlite3 表中?

转载 作者:行者123 更新时间:2023-11-30 02:37:16 24 4
gpt4 key购买 nike

我正在编写一个 Android 应用程序。我有一个 base64 编码数据字符串,我想将它存储在我的 sqlite3 表中。我正在尝试执行以下操作:

SQLiteDatabase db = new MyDatabase(MyApplication.getContext()).getWritableDatabase();
SQLiteStatement stmt = db.compileStatement("insert into MyTable values($next_id, ?, ?, ?, ?, ?, ?);");
stmt.bindLong(1, id);
stmt.bindString(2, someString);
stmt.bindLong(3, someLong);
stmt.bindLong(4, anotherLong);
stmt.bindLong(5, moreLong);
stmt.bindString(6, base64Data); // the field in question
stmt.execute();

但是我得到这个错误:

(1299) abort at 19 in [insert into MyTable values($next_id, ?, ?, ?, ?, ?, ?);]: NOT NULL constraint failed: MyTable.base64Data

MyTable.base64Data 架构是:base64Data text NOT NULL

我可以在我的调试器中看到 base64Data 不为空,所以我认为我的查询一定没有正确形成。

我还尝试将最后一个问号放在引号中:

SQLiteStatement stmt = db.compileStatement("insert into MyTable values($next_id, ?, ?, ?, ?, ?, \"?\");");

但这并没有解决错误。我需要做什么?

最佳答案

你有七个参数,但只绑定(bind)了六个。

(如果第一列应该自动递增,请使用 NULL 而不是 $next_id。)

关于java - 如何将一串 base64 编码的数据插入到 sqlite3 表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26302917/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com