Java 当JDBC驱动程序未实现PreparedStatement.setBlob()时,如何将BLOB写入数据库
在我使用以下代码将BLOB值写入数据库之后:Java 当JDBC驱动程序未实现PreparedStatement.setBlob()时,如何将BLOB写入数据库,java,sqlite,jdbc,Java,Sqlite,Jdbc,在我使用以下代码将BLOB值写入数据库之后: // bb is of type ByteBuffer Blob blob = new SerialBlob(bb.array()); sqlStatement = "UPDATE Words SET Examples=? WHERE Word=\"" + word + "\""; // c is of type Connection PreparedStatement pstmt = c.prepareSta
// bb is of type ByteBuffer
Blob blob = new SerialBlob(bb.array());
sqlStatement = "UPDATE Words SET Examples=? WHERE Word=\"" + word + "\"";
// c is of type Connection
PreparedStatement pstmt = c.prepareStatement(sqlStatement);
pstmt.setBlob(1, blob);
pstmt.executeUpdate();
c.commit();
我得到了以下错误:
java.sql.SQLException:不是由SQLite JDBC驱动程序实现的
无论我从何处下载此驱动程序,我的问题是您是否知道有任何安全的方法将BLOB值写入SQLite数据库。我想您忘记了为
示例列设置值
st.setAsciiStream(1, fin, (int) file.length());//if you are storing file in database
我想我找到了一个有用的方法。最后我使用了下面的代码,它成功了
pstmt.setBytes(1, blob.getBytes(1, bb.capacity()));
例如,您在哪里设置该值?使用setAsCistream()或setBinaryStream()而不是setBlob()是一种很好的做法