1. 程式人生 > >[異常] com.mysql.jdbc.ServerPreparedStatement.setBinaryStream(ILjava/io/InputStream;J)V

[異常] com.mysql.jdbc.ServerPreparedStatement.setBinaryStream(ILjava/io/InputStream;J)V

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());