Creating a UDR
About this task
The following topics shows you how to create a UDR from a Java™ class.
To create a UDR:
Procedure
-
Write a Java™ class with one or more static method to
be registered as UDRs.
For more information, see Requirements for the Java class.
-
Create an sbspace on the database server to hold the JAR
file that contains the code for the UDR.
For information about creating an sbspace, see the Informix® Administrator's Guide for your database server and the J/Foundation Developer's Guide.
-
Open a JDBC connection.
Make sure the connection object has a database object associated with it. For details, see Connect to the database.
-
Instantiate a UDRManager object and a UDRMetaData object:
UDRManager udrmgr = new UDRManager(myConn); UDRMetaData mdata = new UDRMetaData();
-
Create java.lang.Reflect.Method objects for the
static methods to be registered as UDRs.
In the following example, method1 is an instance that represents the udr1(string, string) method in the Group1 java class; method2 is an instance that represents the udr2(Integer, String, String) method in the Group1 Java™ class:
Class gp1 = Class.forName("Group1"); Method method1 = gp1.getMethod("udr1", new Class[]{String.class, String.class}); Method method2 = gp1.getMethod("udr2", new Class[]{Integer.class, String.class, String.class});
-
Specify which methods to register as UDRs.
The second parameter specifies the SQL name of the UDR:
mdata.setUDR(method1, "group1_udr1"); mdata.setUDR(method2, "group1_udr2");
For more information, see Create UDRs.
-
Specify the JAR file SQL name:
mdata.setJarFileSQLName("group1_jar");
-
If desired, specify a path name where the driver should
place the JAR file in the database server file system:
String pathname = "/work/srv93/examples"; udrmgr.setJarFileTmpPath(pathname);
Make sure the path exists in the database server file system. For more information, see Specify a JAR file temporary path.
-
Install the UDRs in the database server:
udrmgr.createUDRs(mdata, "Group1.jar", "Group1", 0);
For more information, see Create UDRs.
Results
For complete code examples of creating UDRs, see Create UDRs with UDRManager.