android sqlite blob,android – SQLite – 是否可以通过insert语句插入BLOB?

开发者正在创建一个Android应用,并使用SQLite数据库存储位图。在应用安装时,他们希望自动插入一些初始的图像数据。问题在于如何在SQLiteOpenHelper的onCreate()方法中利用SQL脚本插入位图。目前的代码片段展示了如何通过字符串数组定义SQL创建和删除脚本,但未明确如何处理位图插入。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我正在开发一个

Android应用程序,我正在使用一个Sqlite数据库来存储一些位图.当用户安装应用程序时,我想要自动插入一些图像.

我正在使用SQLiteOpenHelper类:

public class DatabaseHelper extends SQLiteOpenHelper {

...

DatabaseHelper(Context context, String nameOfDB, int version, String[] scriptSQLCreate,

String scriptSQLDelete) {

super(context, nameOfDB, null, version);

this.scriptSQLCreate = scriptSQLCreate;

this.scriptSQLDelete = scriptSQLDelete;

}

@Override

public void onCreate(SQLiteDatabase db) {

int numScripts = scriptSQLCreate.length;

for(int i = 0; i

Log.i(TAG,"Creating database, executing script " + i);

db.execSQL(scriptSQLCreate[i]);

}

}

}

我想传递一个常量到上面显示的scriptSQLCreate参数,就像这样:

private static final String[] SCRIPT_DATABASE_CREATE = {

"create table memes( id integer primary key autoincrement," +

+ " img blob not null," +

+ " name text not null unique)" ,

"insert into memes(img,name) values(BITMAP1,'1.jpg')",

"insert into memes(img,name) values(BITMAP2,'2.jpg')",

"insert into memes(img,name) values(BITMAP3,'3.jpg')"}

}

任何帮助将会很多,

谢谢,

Tulio Zahn

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值