Home > Database > Mysql Tutorial > body text

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

王林
Release: 2023-09-02 08:53:02
forward
1075 people have browsed it

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!