首页
人工智能
编程教程
编程导航
编程百科
编程问答
编程博文
编程实例
硬件设备
网络运营
软件教程
移动数码
办公软件
操作系统
网络运维
SQLite存取图片
Sqlite
2020-06-21
//向
数据库
中插入数据信息 public long inserUser(User user) { // 获得
sql
iteDatebase进行
数据库
操作 db = dbHelper.getWritableDatabase(); // 参数绑定对象 values = new ContentValues(); values.put(DBInfo.Table.USER_ID,user.getUser_id()); values.put(DBInfo.Table.USER_NAME,user.getUser_name()); values.put(DBInfo.Table.TOKEN,user.getToken()); values.put(DBInfo.Table.TOKEN_SECRET,user.getToken_secret()); values.put(DBInfo.Table.DESCRIPTION,user.getDescription()); //
图片
向
sql
ite
数据库
中进行插入的时候进行的转换操作 userHead 变量类型 Drawable // 将
图片
类型的数据进行存储的时候,需要进行转换才能存储到BLOB类型中 ByteArrayOutputStream os = new ByteArrayOutputStream(); // 为了实现数据存储,需要将数据类型进行转换 BitmapDrawable newHead = (BitmapDrawable) user.getUser_head(); // 将数据进行压缩成PNG编码数据,存储质量100% newHead.getBitmap().compress(CompressFormat.PNG,100,os); // 存储
图片
类型数据 values.put(DBInfo.Table.USER_HEAD,os.toByteArray()); // 进行插入操作,返回行号 long rowId = db.insert(DBInfo.Table.USER_TABLE,DBInfo.Table.USER_NAME,values); // 释放资源 db.close(); return rowId; } //从
数据库
中读取所有
用户
信息 public List<User> findAllUsers() { db = dbHelper.getReadableDatabase(); List<User> userList = null; User user = null; Cursor cursor = db.query(DBInfo.Table.USER_TABLE,columns,null,null); if (cursor != null && cursor.getCount() > 0) { userList = new ArrayList<User>(cursor.getCount()); while (cursor.mov
eto
Next()) { user = new User(); user.setId(cursor.getLong(cursor .getColumnIndex(DBInfo.Table._ID))); user.setUser_id(cursor.getString(cursor .getColumnIndex(DBInfo.Table.USER_ID))); user.setUser_name(cursor.getString(cursor .getColumnIndex(DBInfo.Table.USER_NAME))); user.setToken(cursor.getString(cursor .getColumnIndex(DBInfo.Table.TOKEN))); user.setToken_secret(cursor.getString(cursor .getColumnIndex(DBInfo.Table.TOKEN_SECRET))); user.setDescription(cursor.getString(cursor .getColumnIndex(DBInfo.Table.DESCRIPTION))); //从
数据库
中对数据进行读取 byte[] byteHead = cursor.getBlob(cursor .getColumnIndex(DBInfo.Table.USER_HEAD)); ByteArrayInputStream is = new ByteArrayInputStream(byteHead); Drawable userHead = Drawable.createFromStream(is,"image"); user.setUser_head(userHead); userList.add(user); } } cursor.close(); db.close(); return userList; } } //程序中
获取
ImageView对象 private ImageView user_head;
相关文章
Java 嵌入数据处理引擎:SQLite 的挑战者 esProc SPL
SQLite架构简单,又有Json计算能力,有时会承担Json文件/RES...
五、使用Python操作数据库
使用Python操作内置数据库SQLite以及MySQL数据库。
AndroidStudio-实现登录界面数据存储在SQLite
登陆界面
一文教会你导出微信聊天记录
破解微信数据库密码,用python导出微信聊天记录
UnitySqlite持久化数据
(Unity)SQLite 是一个软件库,实现了自给自足的、无服务器...
Android用户登陆与注册功能的简单实现SQLite
安卓开发,利用SQLite实现登陆注册功能