Feb 04

Depending on your jdbc driver version the following code can fail to run.

File file = new File("image.jpg");
InputStream in = new FileInputStream(file);
preparedStatment.setBinaryStream(1, in, file.length());

The error you will see is as follows.

java.lang.AbstractMethodError: com.mysql.jdbc.ServerPreparedStatement.setBinaryStream(ILjava/io/InputStream;J)V

To fix this problem you need to change the call to setBinaryStream so the last parameter is passed as an integer instead of a long.

File file = new File("image.jpg");
InputStream in = new FileInputStream(file);
preparedStatment.setBinaryStream(1, in, (int) file.length());

written by objects \\ tags: , , ,


6 Responses to “Getting AbstractMethodError when calling setBinaryStream”

  1. André Says:

    Took me half a day to find your post and solve the problem.

    I did see this under tomcat connection pooling:

    java.lang.AbstractMethodError: org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.setBinaryStream(ILjava/io/InputStream;J)V

    But the cause was the same.

    Thanks.

  2. objects Says:

    Glad it helped you.

  3. anyhow Says:

    that works!
    I also get the same type of exception from the connection pool:

    java.lang.AbstractMethodError: org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.setBinaryStream(ILjava/io/InputStream;J)V

    at first i use:preparedStatment.setBinaryStream(1, inputStream);
    then i change that into:preparedStatment.setBinaryStream(1, in, 1000000);

    for i don’t know how to get the size of the stream conveniently,i use 1000000 instead.

  4. Kishor Kumar Says:

    Thankyou
    Your tip works. Thankyou very much.

  5. mayiqun Says:

    thank you , help much

  6. luis55_2 Says:

    Gracias me sirvio de mucho y pensar que solo era un simple casteo….

Leave a Reply