使用Java代码将图片插入数据库(sqlite).我应该怎么办? [英] insert a picture into database(sqlite) with java code. what should i do?

查看:94
本文介绍了使用Java代码将图片插入数据库(sqlite).我应该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在sqlite数据库中,我设置了一个字段类型的blob.然后,我编写了Java代码:

in the sqlite database, i set a field typed blob. then, i wrote java code:

PreparedStatement preStmt = con.prepareStatement("INSERT INTO zz(pic) VALUES(?)");
preStmt.setBinaryStream(1, new FileInputStream(file), file.length());

我有一个例外:

java.lang.AbstractMethodError: org.sqlite.PrepStmt.setBinaryStream(ILjava/io/InputStream;J)V

有什么建议吗?

或者,如果我想在sqlite中使用保存二进制数,我应该写什么代码?

Or, what code i should write if i want to use save binary number in sqlite ?

推荐答案

我使用来自xerial.org的sqlite jdbc dirver取得了成功:

I've had good success with the sqlite jdbc dirver from xerial.org: http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC

Xerial的SQLite JDBC实现具有PreparedStatement.setBytes(index,byte []).您应该能够使用以下链接上的代码从FileInputStream中获取字节数组:

Xerial's SQLite JDBC implementation has PreparedStatement.setBytes(index, byte[]). You should be able to get a byte array from your FileInputStream using the code on the following link: 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

When storing things as Blobs be careful of the following issues: http://effbot.org/zone/sqlite-blob.htm

我希望这会有所帮助.

-亚历克斯

这篇关于使用Java代码将图片插入数据库(sqlite).我应该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆