JDBC保存InputStream流时异常:
java.lang.AbstractMethodError: com.mysql.jdbc.ServerPreparedStatement.setBinaryStream(ILjava/io/InputStream;J)V
异常处理方案:
Depending on your jdbc driver version the following code can fail to run.
译:根据你的JDBC驱动程序版本,下面的代码可以运行失败。
<span style="font-size:14px;">File file = new File("image.jpg");
InputStream in = new FileInputStream(file);
preparedStatment.setBinaryStream(1, in);</span>
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.
译:为了解决这个问题,你需要改变setbinarystream那么最后一个参数。
File file = new File("image.jpg");
InputStream in = new FileInputStream(file);
preparedStatment.setBinaryStream(1, in, (int) file.length());