getBytes vs getBinaryStream vs getBlob用于从BLOB列中获取数据 [英] getBytes vs getBinaryStream vs getBlob for getting data out of a BLOB column
问题描述
有3种不同的方法可以从ResultSet
There are 3 different ways to get data out of a BLOB
column from a ResultSet
-
getBytes
-
getBinaryStream
-
getBlob
getBytes
getBinaryStream
getBlob
此外,getBlob
返回的Blob
对象还具有getBytes
和getBinaryStream
方法.
Also, the Blob
object returned by getBlob
also has getBytes
and getBinaryStream
methods available on it.
我是否有任何特殊原因(性能,内存,数据库特定问题)我应该选择一个?
Are there any particular reasons (performance, memory, database specific problems) that I should pick one over the other?
Blob
对象还具有从JDBC 4.0开始引入的free()
调用.会有所不同吗?
The Blob
object also has a free()
call that has been introduced since JDBC 4.0. Does that make a difference?
推荐答案
如果您要提取大量数据(即,足以导致内存问题的数据),那么getBinaryStream将为您提供最大的灵活性来处理和丢弃读入时的数据.
If you're going to be pulling a lot of data (i.e. enough data to cause memory problems), then getBinaryStream will give you most flexibility to process and discard the data as you read it in.
另一方面,这可能会很慢,具体取决于您的JDBC驱动程序,因为每次从流中读取数据都可能导致数据库与网络进行大量的网络聊天.如果调用getBytes,则驱动程序会知道一次性获取全部内容,这可能会更有效率.
On the other hand, this could be quite slow, depending on your JDBC driver, since each read from the stream could entail a lot of network chatter with the database. If you call getBytes, then the driver knows to fetch the whole lot in one go, which is likely to be more efficient.
getBlob()向数据返回一个指针",您可以使用Blob接口上的方法对其进行操作.如果您需要修改数据或以其他方式欣赏原位数据,那么这可能是最适合您的.
getBlob() returns a "pointer" to the data, which you can manipulate using the methods on the Blob interface. If you need to modify or otherwise get fancy with the data in-situ, then this might be best for you.
这篇关于getBytes vs getBinaryStream vs getBlob用于从BLOB列中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!