JDBC user defined data types

9
JDBC User- Defined Data Types Thanh Nguyen

Transcript of JDBC user defined data types

Page 1: JDBC user defined data types

JDBC User-Defined Data Types

Thanh Nguyen

Page 2: JDBC user defined data types

Instructions

• In Mule 3.6 and newer, you can use user-defined data types with the Database connector

• This feature provides the ability to use JDBC supported types in a query; for example, array, struct, and other types

Page 3: JDBC user defined data types

Instructions

• To use a JDBC data type, specify the type in the database configuration by the name of the type, along with type ID corresponding to the structured data type

Page 4: JDBC user defined data types

Struct Type

• If you created a type in your database using the syntax CREATE TYPE xyz AS OBJECT you have created a struct

• The database connector understands this as java.sql.Struct

• In order to obtain the information about the struct, use MEL to invoke the getAttributes method of this Java type

Page 5: JDBC user defined data types

Array Type

• For array values, the connector returns java.sql.Array• In order to obtain the corresponding Java array,

invoke the getArray method on the java.sql.Array instance

• This requires an open connection to the database, which means that the query returning the array must be executed inside a transactional scope or using streaming, checking the box in the connector properties pane

Page 6: JDBC user defined data types

Passing User-Defined Data Types to Stored Procedure

• To pass a user-defined data type to a stored procedure, the data type should be specified in the database configuration with a number id identifying the JDBC type it conforms to

• The parameter you pass to the stored procedure should be referenced by the name of the data type

Page 7: JDBC user defined data types

Passing User-Defined Data Types to Stored Procedure

Page 8: JDBC user defined data types

Example MEL Expression for Database URL

Page 9: JDBC user defined data types

Question and answer