@echo off
rem (c) Copyright IBM Corp. 2007 All rights reserved.
rem 
rem The following sample of source code ("Sample") is owned by International 
rem Business Machines Corporation or one of its subsidiaries ("IBM") and is 
rem copyrighted and licensed, not sold. You may use, copy, modify, and 
rem distribute the Sample in any form without payment to IBM, for the purpose of 
rem assisting you in the development of your applications.
rem 
rem The Sample code is provided to you on an "AS IS" basis, without warranty of 
rem any kind. IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR 
rem IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
rem MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Some jurisdictions do 
rem not allow for the exclusion or limitation of implied warranties, so the above 
rem limitations or exclusions may not apply to you. IBM shall not be liable for 
rem any damages you suffer as a result of using, copying, modifying or 
rem distributing the Sample, even if IBM has been advised of the possibility of 
rem such damages.

rem BATCH FILE: udfcat.bat
rem To catalog JDBC and SQLJ user-defined functions on Windows
rem Catalogs the User-defined functions in the UDFsrv library
rem UDFDrop.db2 uncatalogs the functions if previously cataloged
rem UDFCreate.db2 catologs the user-defined functions
rem Both CLP scripts can be run on their own
rem Usage: udfcat

rem Uncatalog the functions if previously cataloged
db2 -td@ -vf UDFDrop.db2

rem Connect to 'sample' database
db2 connect to sample

rem Uninstall the jar file if already installed
db2 "CALL sqlj.remove_jar('MYJAR1')"

rem Remove the jar file if already exists
del UDFsrv.jar

rem Create a jar file 'UDFsrv.jar' using the class file 'UDFsrv.class'
echo "Executing 'javac UDFsrv.java'..."
javac UDFsrv.java

echo "Executing 'jar cf UDFsrv.jar UDFsrv.class'..."
jar cf %DB2PATH%\UDFsrv.jar UDFsrv.class Person.class

rem Install the jar file using a unique jar-id.
db2 "CALL sqlj.install_jar('file:%DB2PATH%\UDFsrv.jar', 'MYJAR1')"

rem Disconnect from 'sample' database
db2 connect reset

rem Catalog the user-defined functions
db2 -td@ -vf UDFCreate.db2

@echo on