2

I'm trying to store MediumBlob data in MySQL using java. But I have no success to retrieve the data.

To store I'm using:

PreparedStatement = stmt conn.prepareStatement("UPDATE INTO table VALUE(?)");
ByteArrayInputStream bais = new ByteArrayInputStream(data);
stmt.setBinaryStream(position, bais, data.length);

Is there correcty?

6
  • Does it get into the database correctly? When you say you have no success retrieving the data what do you mean? Commented Feb 24, 2011 at 14:38
  • have you tried setBlob() instead of setbinaryStream() ? Commented Feb 24, 2011 at 14:45
  • Using setBlob() a exception occurs when I call stmt.update() Commented Feb 24, 2011 at 14:55
  • @jzd some data is returned by the databse, but is not the data that I have on setBinaryData. Is something different... :( Commented Feb 24, 2011 at 14:55
  • @Victor, what is the exception you are getting with setBlob()? Commented Feb 24, 2011 at 14:57

1 Answer 1

1

I fix it!!!!

The problem was when I was retrieving the data. I was calling:

ResultSet.getClob

But I should call:

ResultSet.getBinaryStream

I have used setBinaryStream to input data!

This was confusing because I have a Clob field, and I was expecting retrieving a Clob field in Java code!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.