Jan 30

That can be achieved with a PreparedStatement and its setBytes() method.

String sql = "INSERT INTO my_table (byte_array) VALUES (?)";
PreparedStatement statement = connection.prepareStatement(sql);
byte[] buffer = somwhere.getSomeByteArray();
statement.setBytes(1, buffer);

written by objects

Array ( ) 2 Responses to “How to add byte array to database with JDBC?”

  1. Brendan Loyot Says:


    I’m just wondering what type that should be stored as in the database. I was trying to store it first as a blob, but I get a type mismatch exception. I hope that question makes sense, I’m fairly new to db stuff and sql/jdbc.


  2. objects Says:

    blob should be fine. post your code and the exception and we’ll have a look at it for you

Leave a Reply

You must be logged in to post a comment.