Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inserting byte array into blob column

Tags:

java

sqlite

jdbc

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!

Here's my code:

 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();
    }
like image 379
Irina Avatar asked Mar 27 '26 06:03

Irina


1 Answers

Once a PreparedStatement object has been created with

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

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();

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

like image 184
Gord Thompson Avatar answered Mar 28 '26 18:03

Gord Thompson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!