Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do java.sql.Array/Blob/Clob types need to be "free()"ed?

Tags:

java

jdbc

blob

clob

Do I need an explicit to call free() on Arrays, clobs etc... or will closing the ResultSet and/or Statement automatically take care of this? The javadoc doesn't say anything, so I assume that it's not necessary, but I would hate to make an incorrect assumption.

Also, if its not necessary, is it a good idea if you're going to close the result set right away? I could see how it might help if you're not going to do so.

like image 441
Bill Avatar asked Sep 11 '12 04:09

Bill


People also ask

How is CLOB datatype defined in Java?

An SQL CLOB is a built-in type that stores a Character Large Object as a column value in a row of a database table. By default drivers implement a Clob object using an SQL locator(CLOB) , which means that a Clob object contains a logical pointer to the SQL CLOB data rather than the data itself.

How do you read a CLOB column in Java?

To read from a CLOB, use the getAsciiStream() or getCharacterStream() method of an oracle. sql. CLOB object to retrieve the entire CLOB as an input stream. The getAsciiStream() method returns an ASCII input stream in a java.

What is the use of BLOB CLOB datatypes in JDBC?

BLOBs are used to store binary information, such as images, while CLOBs are used to store character information. BLOBs and CLOBs can store up to 4 Gigabytes of data (the limit imposed by the JDBC and ODBC specifications).

Where can BLOB CLOB array and Ref type columns be updated?

The JDBC API is a constituent technology of the Java platform. The JDBC 3.0 API should be aligned with the overall direction of the Java 2 Enterprise Edition and Java 2 Standard Edition platforms.


1 Answers

It depends on the Vendor and JDBC version you are using. As all databse vendors do not support Array(e.g. MySQL)

And this could be the reason Why the javadoc doesn't say anything.

I have found this tutorial Using Array Object on oracle site's JavaSE tutorials which says to release resources explicitly.

Here is another link which illustrates scenario of on free(). JDBC 4's java.sql.Clob.free() method and backwards compatibility

if its not necessary, is it a good idea if you're going to close the result set right away?

I think then there should not be required to free(),but again if its a long running transcation,then its good to call free().

Quoting from the tutorial:

Array objects remain valid for at least the duration of the transaction in which they are created. This could potentially result in an application running out of resources during a long running transaction. Applications may release Array resources by invoking their free method.

like image 127
Hardik Mishra Avatar answered Sep 21 '22 23:09

Hardik Mishra