// Source File Name: DELPHUdf.java %I% // // Licensed Materials -- Property of IBM // // (c) Copyright International Business Machines Corporation, 1996, 1999. // All Rights Reserved. // // US Government Users Restricted Rights - // Use, duplication or disclosure restricted by // GSA ADP Schedule Contract with IBM Corp. // Sample program - Java User-defined Functions // Steps to set up the server side: // (1) create and populate the SAMPLE database (db2sampl) // (2) compile this Java file (javac DELPHUdf.java) // (3) copy the resulting DELPHUdf.class file into sqllib/function // NOTES: (1) The jdk11_path database manager configuration parameter must // be set // (2) The CLASSPATH and shared library path environment variables // must be set, as for any JDBC application. // (3) Visit http://www.software.ibm.com/data/db2/java // for current DB2 Java information // Class DB2UdCli implements the sample client (configuration and // execution using JDBC). Class DELPHUdf implements the UDF // method bodies. // DELPHUdf uses the LOB support provided by the COM.ibm.db2.app.* package. // Since JDK1.2 also provides LOB support, references to objects of type // Lob, Blob, and Clob must be explicitly type-decorated to compile on a // system with JDK1.2 support. This sample uses the COM.ibm.db2.app.* LOB // support to provide compatibility for both JDK1.1 and JDK1.2 systems. // For more information about this sample, refer to the README file. // For more information on programming in Java, refer to the // "Programming in Java" section of the Application Development Guide. // For more information on creating and using user-defined functions, // refer to the "Object-Relational Programming" section of the // Application Development Guide. // For more information on building and running Java programs for DB2, // refer to the "Building Java Applets and Applications" section of the // Application Building Guide. // For more information on the SQL language, refer to the SQL Reference. import COM.ibm.db2.app.*; import COM.ibm.db2.jdbc.app.*; import java.sql.*; import java.io.*; import java.net.*; import java.util.*; /////// // Java user-defined functions are in this class /////// class DELPHUdf extends UDF { /////// // Translations of C UDFs /////// // Integer division example. // Returns Patent number reformatted to JAPIO standards. public void npopatn (String a, String result) throws Exception { String patn = ""; int ptnlen = a.length(); if (Character.isLetter(a.charAt(2))) { if (Character.isDigit(a.charAt(3))) { patn="US0"+a.substring(2,3)+a.substring(4,ptnlen); } else { patn="US0"+a.substring(2,4)+a.substring(5,ptnlen); } } if (Character.isDigit(a.charAt(2))) { set (2,a.trim()); return; } set (2,patn.trim()); return; } public void noblank (String a, String result) throws Exception { String newa = ""; if (a.length() == 0) { set (2,a.trim()); return; } StringTokenizer st = new StringTokenizer(a, " "); if (st.countTokens() == 0) { set (2,a.trim()); return; } else { int j = st.countTokens(); for (int i=0;i