将字节数组插入blob列 [英] inserting byte array into blob column

查看:99
本文介绍了将字节数组插入blob列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将字节数组插入sqlite数据库中的blob列。我已尝试使用setBinaryStream和setBytes,但我没有通过SQLite JDBC驱动程序异常实现。我正在使用sqlite-jdbc-3.8.7.jar。我应该用什么jar来实现这项工作?谢谢!

I'm trying to insert byte array into a blob column in sqlite database. I've tried with both setBinaryStream and setBytes, but I'm getting not implemented by SQLite JDBC driver exception. I'm using sqlite-jdbc-3.8.7.jar.What jar should I use to get this work? Thanks!

这是我的代码:

 public void addDriverData(String prenume,String nume,String telefon,String email,String permis,String parola,byte[] photo) throws SQLException
    { String sql = "INSERT INTO driver(first_name,last_name,phone,email,permit,password,photo)VALUES(?,?,?,?,?,?,?)";
        PreparedStatement stm = c.prepareStatement(sql);
        stm.setString(1,prenume);
        stm.setString(2,nume);
        stm.setString(3,telefon);
        stm.setString(4,email);
        stm.setString(5,permis);
        stm.setString(6, parola);
        //stm.setBinaryStream(7,new ByteArrayInputStream(photo),photo.length);
        stm.setBytes(7, photo);

        System.out.println(sql);
        stm.executeUpdate(sql);
        stm.close();
        c.commit();
    }


推荐答案

一旦 PreparedStatement 已使用

String sql = "INSERT INTO ...";
PreparedStatement stm = c.prepareStatement(sql);

对象已处理 sql 命令文本。当执行PreparedStatement时,我们需要做的就是

the object has already processed the sql command text. When the time comes to execute the PreparedStatement all we need to do is

stm.executeUpdate();

(方法调用 executeUpdate(sql)旨在与 Statement 对象一起使用,而不是 PreparedStatement 对象。)

(The method call executeUpdate(sql) is intended to be used with Statement objects, not PreparedStatement objects.)

这篇关于将字节数组插入blob列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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