在 sqlite 数据库中,我设置了一个类型为 blob 的字段。 然后,我写了java代码:
PreparedStatement preStmt = con.prepareStatement("INSERT INTO zz(pic) VALUES(?)");
preStmt.setBinaryStream(1, new FileInputStream(file), file.length());
我有一个异常(exception):
java.lang.AbstractMethodError: org.sqlite.PrepStmt.setBinaryStream(ILjava/io/InputStream;J)V
有什么建议吗?
或者,如果我想在 sqlite 中使用保存二进制数,我应该写什么代码?
最佳答案
我在 xerial.org 的 sqlite jdbc dirver 上取得了很好的成功:http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC
Xerial 的 SQLite JDBC 实现有 PreparedStatement.setBytes(index, byte[])。您应该能够使用以下链接中的代码从 FileInputStream 获取字节数组:http://www.java-tips.org/java-se-tips/java.io/reading-a-file-into-a-byte-array.html
将事物存储为 Blob 时要注意以下问题:http://effbot.org/zone/sqlite-blob.htm
希望对您有所帮助。
-亚历克斯
关于java - 使用java代码将图片插入数据库(sqlite)。我应该怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2182467/