Skip to content

Commit 50e5776

Browse files
fix: improve oracle
1 parent 97411dd commit 50e5776

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

framework-docs/modules/ROOT/pages/data-access/jdbc/parameter-handling.adoc

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ are passed in as a parameter to the stored procedure.
209209

210210
The `SqlReturnType` interface has a single method (named `getTypeValue`) that must be
211211
implemented. This interface is used as part of the declaration of an `SqlOutParameter`.
212-
The following example shows returning the value of an Oracle `STRUCT` object of the user
212+
The following example shows returning the value of a `java.sql.Struct` object of the user
213213
declared type `ITEM_TYPE`:
214214

215215
[tabs]
@@ -222,9 +222,9 @@ Java::
222222
223223
public TestItemStoredProcedure(DataSource dataSource) {
224224
// ...
225-
declareParameter(new SqlOutParameter("item", OracleTypes.STRUCT, "ITEM_TYPE",
225+
declareParameter(new SqlOutParameter("item", Types.STRUCT, "ITEM_TYPE",
226226
(CallableStatement cs, int colIndx, int sqlType, String typeName) -> {
227-
STRUCT struct = (STRUCT) cs.getObject(colIndx);
227+
Struct struct = (Struct) cs.getObject(colIndx);
228228
Object[] attr = struct.getAttributes();
229229
TestItem item = new TestItem();
230230
item.setId(((Number) attr[0]).longValue());
@@ -258,8 +258,8 @@ Kotlin::
258258
You can use `SqlTypeValue` to pass the value of a Java object (such as `TestItem`) to a
259259
stored procedure. The `SqlTypeValue` interface has a single method (named
260260
`createTypeValue`) that you must implement. The active connection is passed in, and you
261-
can use it to create database-specific objects, such as `StructDescriptor` instances
262-
or `ArrayDescriptor` instances. The following example creates a `StructDescriptor` instance:
261+
can use it to create database-specific objects, such as `java.sql.Struct` instances
262+
or `java.sql.Array` instances. The following example creates a `java.sql.Struct` instance:
263263

264264
[tabs]
265265
======
@@ -272,14 +272,12 @@ Java::
272272
273273
SqlTypeValue value = new AbstractSqlTypeValue() {
274274
protected Object createTypeValue(Connection conn, int sqlType, String typeName) throws SQLException {
275-
StructDescriptor itemDescriptor = new StructDescriptor(typeName, conn);
276-
Struct item = new STRUCT(itemDescriptor, conn,
277-
new Object[] {
275+
var item = new Object[] {
278276
testItem.getId(),
279277
testItem.getDescription(),
280278
new java.sql.Date(testItem.getExpirationDate().getTime())
281-
});
282-
return item;
279+
};
280+
return connection.createStruct(typeName, objects);
283281
}
284282
};
285283
----
@@ -307,7 +305,7 @@ You can now add this `SqlTypeValue` to the `Map` that contains the input paramet
307305
Another use for the `SqlTypeValue` is passing in an array of values to an Oracle stored
308306
procedure. Oracle has its own internal `ARRAY` class that must be used in this case, and
309307
you can use the `SqlTypeValue` to create an instance of the Oracle `ARRAY` and populate
310-
it with values from the Java `ARRAY`, as the following example shows:
308+
it with values from the Java `java.sql.Array`, as the following example shows:
311309

312310
[tabs]
313311
======
@@ -319,9 +317,7 @@ Java::
319317
320318
SqlTypeValue value = new AbstractSqlTypeValue() {
321319
protected Object createTypeValue(Connection conn, int sqlType, String typeName) throws SQLException {
322-
ArrayDescriptor arrayDescriptor = new ArrayDescriptor(typeName, conn);
323-
ARRAY idArray = new ARRAY(arrayDescriptor, conn, ids);
324-
return idArray;
320+
return conn.unwrap(OracleConnection.class).createOracleArray(typeName, ids);
325321
}
326322
};
327323
----

0 commit comments

Comments
 (0)