getArrayをコールした後freeメソッドでは一時LOBを開放しない場合がある
(Doc ID 2127918.1)
Last updated on AUGUST 28, 2019
適用範囲:
JDBC - バージョン 11.2.0.1.0 以降この文書の内容はすべてのプラットフォームに適用されます。
現象
ストアド・プロシージャに IN OUT の LOB パラメータがあり、このパラメータに値を設定するために setARRAY を使用するとします。getArray を使用してデータを取得した後、free メソッドをコールして一時 LOB を開放します。しかし Java ヒープダンプを確認すると、その一時 LOB に関連付けられたメモリが開放されていません。
次はこの問題を示すテストです。
1. 次のように、LOB の配列オブジェクトを作成し、ストアド・プロシージャの IN OUT LOB パラメータとして使用します。
CREATE OR REPLACE TYPE ARRAY_BLOB AS TABLE OF BLOB;
CREATE OR REPLACE PROCEDURE testBlobArray(objs in out nocopy ARRAY_BLOB) IS
BEGIN
DBMS_OUTPUT.PUT_LINE('hello');
END;
CREATE OR REPLACE PROCEDURE testBlobArray(objs in out nocopy ARRAY_BLOB) IS
BEGIN
DBMS_OUTPUT.PUT_LINE('hello');
END;
2. JDBC 経由してストアド・プロシージャを実行できるように、次の java プログラムを作成します。
//prepare statement
stmt = (OracleCallableStatement) conn.prepareCall("{call testBlobArray(?)}");
//create the temporary LOB
BLOB blob = BLOB.createTemporary(connection, true, BLOB.DURATION_SESSION);
OutputStream outstm = blob.getBinaryOutputStream();
blob.open(BLOB.MODE_READWRITE);
outstm.write(bytes);
outstm.flush();
//construct the ARRAY object
ArrayDescriptor des = ArrayDescriptor.createDescriptor("ARRAY_BLOB",connection);
ARRAY arr = new ARRAY(des,connection,{blob});
//use setARRAY to pass the array to the stored procedure
stmt.setARRAY(1, arr);
//register the OUT parameter and execute
stmt.registerOutParameter(1, OracleTypes.ARRAY, "ARRAY_BLOB");
stmt.execute();
//call getArray to retrieve the data
Object[] arrayObje = (Object[]) stmt.getARRAY(1).getArray();
//free the temporary LOB
blob.free();
stmt = (OracleCallableStatement) conn.prepareCall("{call testBlobArray(?)}");
//create the temporary LOB
BLOB blob = BLOB.createTemporary(connection, true, BLOB.DURATION_SESSION);
OutputStream outstm = blob.getBinaryOutputStream();
blob.open(BLOB.MODE_READWRITE);
outstm.write(bytes);
outstm.flush();
//construct the ARRAY object
ArrayDescriptor des = ArrayDescriptor.createDescriptor("ARRAY_BLOB",connection);
ARRAY arr = new ARRAY(des,connection,{blob});
//use setARRAY to pass the array to the stored procedure
stmt.setARRAY(1, arr);
//register the OUT parameter and execute
stmt.registerOutParameter(1, OracleTypes.ARRAY, "ARRAY_BLOB");
stmt.execute();
//call getArray to retrieve the data
Object[] arrayObje = (Object[]) stmt.getARRAY(1).getArray();
//free the temporary LOB
blob.free();
3. java プログラムを実行し、Java ヒープダンプよりメモリを確認します。
原因
To view full details, sign in with your My Oracle Support account. |
|
Don't have a My Oracle Support account? Click to get started! |
本書の内容
現象 |
原因 |
解決策 |
参照情報 |