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());
Array ( ) 11 Responses to “Getting AbstractMethodError when calling setBinaryStream”
Leave a Reply
You must be logged in to post a comment.
March 3rd, 2010 at 2:08 am
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.
March 3rd, 2010 at 8:04 am
Glad it helped you.
May 31st, 2010 at 3:19 am
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.
August 20th, 2010 at 9:27 am
Thankyou
Your tip works. Thankyou very much.
November 18th, 2010 at 9:01 pm
thank you , help much
April 17th, 2011 at 12:25 pm
Gracias me sirvio de mucho y pensar que solo era un simple casteo….
June 4th, 2012 at 9:09 pm
Thank you very much. I wasted almost 3 hours trying to figure out the issue
June 26th, 2012 at 2:59 am
It Works! Thanks a lot ^_^ …
I tried with an inputstream from an excel workbook (instead a file, created with Apache POI), and i don’t know the size of the document and get this error. I have saved the document in file and then create the inputStream from this file.
It works!
You think there is an alternative way to determine the size of a generic stream?
thanks in advance đŸ˜‰
June 26th, 2012 at 2:25 pm
Only way to find the length of a generic stream is to read it (until eof)
In your case can’t you get the size of the source excel workbook?
February 19th, 2013 at 4:37 am
Is there any way to have a real streaming, so not anything would be in memory?
October 7th, 2014 at 7:10 am
Boss you saved my big time thank youuuuuuuuuuuuu