Home >Database >Mysql Tutorial >What is the difference between setBlob() and setBinaryStream() methods, and which one is preferable in JDBC?

What is the difference between setBlob() and setBinaryStream() methods, and which one is preferable in JDBC?

王林
王林forward
2023-09-02 08:53:021177browse

setBlob() 和 setBinaryStream() 方法之间有什么区别,哪个在 JDBC 中更可取?

The setBlob() method is used to set the value of the Blob data type in the database. It has the following three variants:

  • void setBlob(int parameterIndex, Blob x): Sets the given Blob value to the parameter

  • void setBlob(int parameterIndex, InputStream inputStream): Sets the contents of the given input stream to the value of the parameter at the specified index.

  • void setBlob(int parameterIndex, InputStream inputStream, long length): Sets the contents of the given input stream to the parameter with a value up to the specified index.

setBinaryStream()The method is used to set the contents of the given InputStream to the parameter at the specified index. It has the following three variants:

  • void setBinaryStream(int parameterIndex, InputStream x): Sets the contents of the given input stream to the parameter at the specified index value.

  • void setBinaryStream(intparameterIndex, InputStream x, int length): ): Sets the given input stream (which will have the specified number of bytes) as the specified index The value of the parameter.

  • void setBinaryStream(int parameterIndex, InputStream x, long length): Set the contents of the given input stream (which will have the specified number of bytes) to the specified index The value of the parameter at.

The main difference between these two methods is that the setBlob() method indicates to the driver that the parameter value should be sent to the server as a BLOB data type.

Like the setBinaryStream() method, the driver first determines in which format the value should be sent (LONGVARBINARY or BLOB), and then sends it to the server.

The above is the detailed content of What is the difference between setBlob() and setBinaryStream() methods, and which one is preferable in JDBC?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete