- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我尝试在 sqlite 数据库中存储和检索图像。我的以下代码不起作用。我不确定我做错了什么。请帮忙。我创建的数据库表如下:
db = openOrCreateDatabase("StudentDB", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS student(rollno VARCHAR,
name VARCHAR,photo BLOB,marks VARCHAR);");
然后我插入字段
db.execSQL("INSERT INTO student VALUES('"
+ editRollno.getText() + "','"
+ editName.getText() + "','"
+ imageInByte + "','"
+ editMarks.getText() 方法
+ "');");
其中 imageInByte 是一个 byte[] 变量,之前从 gallery 中分配如下:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
yourImage.compress(Bitmap.CompressFormat.PNG, 100, stream);
imageInByte = stream.toByteArray();
当我尝试从数据库中检索图像时失败了:
Cursor c = db.rawQuery("SELECT * FROM student WHERE rollno='"
+ editRollno.getText() + "'", null);
if (c.moveToFirst()) {
editName.setText(c.getString(1));
editMarks.setText(c.getString(2));
byte[] image = c.getBlob(3);
ByteArrayInputStream imageStream = new ByteArrayInputStream(image);
theImage = BitmapFactory.decodeStream(imageStream);
imageView2.setImageBitmap(theImage);
}
最佳答案
您不能简单地将字节数组视为文本。(要将 blob 与 execSQL 一起使用,您必须使用 blob 文字。)
要插入一行,请使用 insert method , 其中有 support for byte arrays .
关于android cursor.getBlob 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28811674/
代码: ResultSet rs = null; try { conn = getConnection(); stmt = conn.prepareStatement(sql);
您好,我尝试在 sqlite 数据库中存储和检索图像。我的以下代码不起作用。我不确定我做错了什么。请帮忙。我创建的数据库表如下: db = openOrCreateDatabase("StudentD
我在 Web 应用程序中使用 jclouds 1.6.1-incubating(使用 scala playframework 2.1.3,但这无关紧要)。 由于 jclouds 中接收 blob 的所
我想升级我的项目的jdbc驱动程序。目前我正在使用 ojdbc5.jar。我想升级到ojdbc8.jar。 我注意到读取 blob 现在慢得多。 try (Connection connect
来自数据库 your.db 的表结构 Calcs(SQLite 使用 SQLite Studio): Id: Integer Content: Text // Type is text, not B
本文整理了Java中com.google.gdata.util.XmlBlob.getBlob()方法的一些代码示例,展示了XmlBlob.getBlob()的具体用法。这些代码示例主要来源于Gith
任何人都知道如何使用 GetOptions 从 blob 存储中获取 blob: BlobStore blobStore = context.getBlobStore(); Blob blob = b
我已将 6 GiB 文件作为 4 MiB block 上传到 Azure Blob 存储热层。 当我放置文件时,它将创建 (6000/4) PutBlock * 1 PutBlockList 调用。这
我在应用程序中有一个 .Java 文件,其中的代码如下 blob = ((OracleResultSet) rs).getBLOB("Document"); 我已导入 oracle.sql.blob。
我正在尝试使用 getBlob 方法将图片检索到 byte[]。 但是,如果 blob 超过 2MB,我注意到它会崩溃。 我发现一篇文章说使用 substr 函数来分段获取它,但这不起作用。 这是我的
有 3 种不同的方法可以从 ResultSet 的 BLOB 列中获取数据 getBytes getBinaryStream getBlob 另外,getBlob 返回的 Blob 对象也有 getB
为此,我使用 Azure.Storage.Blobs 版本 12.14...,因为旧版 SDK 已被弃用,并且我们的存储服务代码需要更新。 以下代码(与 Microsoft 文档教程匹配)失败,但不会
我在尝试从 Oracle DB 读取 blob 时遇到问题通过使用这个 rs.getBlob("ARCHIVE_REQ_FILE_BLOB") 我也尝试过这个 oracle.sql.BLOB blob
屏幕截图:getBlob 返回的错误结果: 这里是附加代码: resize(img, img, Size(224, 224)); dnn::Blob inputBlob = dnn::Blob::fr
我是一名优秀的程序员,十分优秀!