Irina
Irina

Reputation: 31

inserting byte array into blob column

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

Upvotes: 3

Views: 6055

Answers (1)

Gord Thompson
Gord Thompson

Reputation: 123409

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.)

Upvotes: 2

Related Questions