@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: bldsqlj.bat
rem Builds a Java embedded SQL (SQLJ) application or applet on Windows

rem To add defaults for user ID (USER) and password (PSWD)
rem Uncomment the following and add the appropriate values
rem set USR=
rem set PSWD=

rem You can replace the defaults for each of the following
rem with a new value. Note that the PORTNUM number cannot be
rem one already used by another process.
set SERVER=%COMPUTERNAME%
set PORTNUM=50000
set DB=sample

goto start
:usage
echo Usage: bldsqlj prog_name (requires hardcoding user ID and password)
echo        bldsqlj prog_name userid password
echo        bldsqlj prog_name userid password server_name
echo        bldsqlj prog_name userid password server_name port_number
echo        bldsqlj prog_name userid password server_name port_number db_name
echo.
echo        Defaults:
echo          userid      = %USR%
echo          password    = %PSWD%
echo          server_name = %SERVER%
echo          port_number = %PORTNUM%
echo          db_name     = %DB%
goto exit

:start
rem Translate and compile the SQLJ source file
rem and bind the package to the database.
if "%1" == "" goto usage
if "%2" == "" goto case1
if "%3" == "" goto usage
if "%4" == "" goto case3
if "%5" == "" goto case4
if "%6" == "" goto case5
if "%7" == "" goto case6
goto usage

:case1
   if "%USR%" == "" goto usage
   if "%PSWD%" == "" goto usage
   if "%SERVER%" == "" goto nohostname
   sqlj %1.sqlj
   db2sqljcustomize -url jdbc:db2://%SERVER%:%PORTNUM%/%DB% -user %USR% -password %PSWD% %1_SJProfile0
   goto continue

:case3
   if "%SERVER%" == "" goto nohostname
   sqlj %1.sqlj
   db2sqljcustomize -url jdbc:db2://%SERVER%:%PORTNUM%/%DB% -user %2 -password %3 %1_SJProfile0
   goto continue

:case4
   sqlj %1.sqlj
   db2sqljcustomize -url jdbc:db2://%4:%PORTNUM%/%DB% -user %2 -password %3 %1_SJProfile0
   goto continue

:case5
   sqlj %1.sqlj
   db2sqljcustomize -url jdbc:db2://%4:%5/%DB% -user %2 -password %3 %1_SJProfile0
   goto continue

:case6
   sqlj %1.sqlj
   db2sqljcustomize -url jdbc:db2://%4:%5/%6 -user %2 -password %3 %1_SJProfile0
   goto continue

:continue
goto exit

:nohostname
echo Server name (hostname) could not be determined.
echo.
goto usage

:exit
@echo on