1

So I am using a java SQL api to insert some BLOB data into a table. However, Since the SQL apparently doesn't know that I just want the string to end, it just pads it with zeros. So I have 10 charachters of data followed by a gazillion zeros at the end. How should I solve this problem, and is all hope lost?

public void storeInTable(String data) throws SQLException{

    statement.executeUpdate("INSERT INTO put.data VALUES ('" + data + "', NOW())");
}

2 Answers2

2

Try with PreparedStatement#setBlob(). learn more...

It's better explained under Oracle Tutorial on Using Large Objects

Here is an example

sample code:

ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
preparedStatement.setBlob(index, bais);
Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76
0

OP here. in case anyone is having the same problem

REPLACE('" + data + "', CHAR(0), '' )

worked for me. You may want to head the other guy's advice and use prepared statements as well.