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); statement.executeUpdate(); statement.close();
Array ( ) 2 Responses to “How to add byte array to database with JDBC?”
Leave a Reply
You must be logged in to post a comment.
April 19th, 2012 at 5:18 pm
Hi,
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.
Thanks!
Brendan
April 19th, 2012 at 5:41 pm
blob should be fine. post your code and the exception and we’ll have a look at it for you