Manage memory for large objects

Whenever a large object (a BYTE, TEXT, BLOB, or CLOB data type) is fetched from the database server, the data is either cached into memory or stored in a temporary file (if it exceeds the memory buffer). A JDBC applet can cause a security violation if it tries to create a temporary file on the local computer. In this case, the entire large object must be stored in memory.

You can specify how large object data is stored by using an environment variable, LOBCACHE, that you include in the connection property list, as follows:
  • To set the maximum number of bytes allocated in memory to hold the data, set the LOBCACHE value to that number of bytes.

    If the data size exceeds the LOBCACHE value, the data is stored in a temporary file. If a security violation occurs during creation of this file, the data is stored in memory.

  • To always store the data in a file, set the LOBCACHE value to 0.

    In this case, if a security violation occurs, Informix® JDBC Driver makes no attempt to store the data in memory. This setting is not supported for unsigned applets. For more information, see Using the driver in an applet.

  • To always store the data in memory, set the LOBCACHE value to a negative number.

    If the required amount of memory is not available, Informix® JDBC Driver throws the SQLException message Out of Memory.

If the LOBCACHE size is invalid or not defined, the default size is 4096.

You can set the LOBCACHE value through the database URL, as follows:
URL = jdbc:informix-sqli://158.58.9.37:7110/test:user=guest;
password=iamaguest;informixserver=oltapshm;
lobcache=4096";

The preceding example stores the large object in memory if the size is 4096 bytes or fewer. If the large object exceeds 4096 bytes, Informix® JDBC Driver tries to create a temporary file. If a security violation occurs, memory is allocated for the entire large object. If that fails, the driver throws an SQLException message.

Here is another example:
URL = "jdbc:informix-sqli://icarus:7110/testdb:
   user=guest:passwd=whoknows;informixserver=olserv01;lobcache=0";

The preceding example uses a temporary file for storing the fetched large object.

Here is a third example:
URL = "jdbc:informix-sqli://icarus:7110/testdb:user=guest:
   passwd=whoknows;informixserver=olserv01;lobcache=-1";

The preceding example always uses memory to store the fetched large object.

For programming information about how to use the TEXT and BYTE data types in a Java program, see BYTE and TEXT data types. For programming information about how to use the BLOB and CLOB data types in a Java program, see Smart large object data types.