Sybase JDBC LookUp Sample
(with NetImpact Dynamo)
This sample will connect to a SQL Anywhere database, look up and display customer information for a
customer whose id number is 101.
To run this sample on your machine, you will need to install the following components:
- NetImpact Dynamo
- Microsoft Java VM
- SQL Anywhere (and a SQL Anywhere database)
- Open Server Gateway components from SQL Anywhere
Server Side Instructions
To configure the Open Server Gateway for a SQL Anywhere Database
- Install the Open Server Gateway components (SQL Anywhere Open Server Gateway and
Sybase Open Server components) when installing SQL Anywhere Server.
- Check that your SYBASE environment variable is set to point to the directory where you've installed
the Open Server Gateway components.
For example: SYBASE = d:\sybase
- Run \sybase\bin\sqledit.exe to provide an Open Server Gateway name for your SQL
Anywhere database and configure your connection profile.
- Click on the Input Server Name box and type the Open Server Gateway name you want to give your
SQL Anywhere database. The convention is to give the Open Server Gateway the same name as your
SQL Anywhere database.
For example: sademo
- Click on Add to add this name to the list of Server Entries.
- From the Service Type list, select query to add a query service
- From the Platform list, select the appropriate platform (NT, dos, or win3).
- From the Net-Library Driver list, select NLWNSCK. This is the WinSock network-library driver.
- Click on the Connection Information/Network Address box. Then type your machine name, a
comma and then the port number where client programs can access this SQL Anywhere database.
Here, you can choose any unused port number.
For example: MNGUYEN, 8000
- Click Add Service to add this query service.
- From the Service Type list, select master to add a master service
- Repeat Steps 7, 8 and 9.
- From the File menu of the main SQLEDIT menu bar, click Save to save this sql.ini file.
Now check that you have the following information in your sql.ini file displayed in SQLEDIT:
- In the Server Entry list, an entry for your SQL Anywhere database resembling:
sademo
- From the Server Entry list, click on the name of your SQL Anywhere database:
sademo
- In the Connection Server Entry list, a query service entry resembling:
query = NLWNSCK, MNGUYEN, 8000
- In the Connection Server Entry list, a master service entry resembling:
master = NLWNSCK, MNGUYEN, 8000
To configure NetImpact Dynamo via SQL Central
- Start SQL Central.
- From the Tools menu of the main SQL Central menu bar, click Connect and then choose NetImpact
Dynamo to connect to NetImpact Dynamo.
- Click in the Connection name box and type
Dynamo Demo
- From the ODBC data source list, select NetImpact Dynamo Demo
- Click in the User ID box and type
dba
- Click in the Password box and type
sql
- Click OK.
- If you want this Dynamo Demo to start up every time you load SQL Central, from the Tools menu of
the main SQL Central menu bar, click Connection Profiles. Then choose Dynamo Demo from the
Connection Profile list. Then click Set Startup. Now, the Use on Startup field should be set to Yes.
Click Close to finish. Please note that this won't take effect until you restart SQL Central.
- Double click on the Dynamo Demo icon.
- Double click on the Site folder, then click on the system folder to go to \Site\system.
- Double click on the autoexec.ssc icon to open it.
- Insert the following statement after the last line of text, but before the line with -->:
site.AddExtension( 'JAVA_DYNAMO', '%Starbuck%/system/javadynamo.dll' );
where %Starbuck% is the directory where you installed Starbuck.
Please note the use of forward slashes in the path.
For example:
site.AddExtension( 'JAVA_DYNAMO', 'd:/starbuck20/system/javadynamo.dll' );
- From the File menu of the editor window for autoexec.ssc, click Save to Database to save
- Close autoexec.ssc
- In the main SQL Central window, use the right button to click on the autoexec.ssc icon. Then
choose Execute to run this script. If there were no errors, the output screen will be blank.
- Click on the Site folder to move to \Site.
- Double click on the Add Template icon to create a new template
- Click in the box for the new template's name and type
DJDBC_Lookup
- Click Next. Enter a description for this template if you wish, then click Next.
- Click Next to not add a SQL statement and then click Finish to accept the default HTML format.
- Double click on the template DJDBC_Lookup.stm icon to open it
- Insert the following statement after the <H1></H1> line:
<!--JAVA_DYNAMO
DJDBC_LookUp
classpath=$%Starbuck%/java/lib;%Starbuck%/samples/DJDBC_LookUp/Debug
host
port
firstName
lastName
-->
The first line in the script is the name of the Java class with main(),
in this case DJDBC_LookUp.
The second line is the classpath to the Java class files. %Starbuck% refers
to the directory where Starbuck is installed.
Please note the use of forward slashes in the path.
The third line is the host name of your computer.
The fourth line is the port number to connect to the SQL Anywhere database
The fifth line is the first name of the customer whose info you want to get
The sixth line is the last name of the customer whose info you want to get
For example:
<!--JAVA_DYNAMO
DJDBC_LookUp
classpath=$d:/starbuck20/java/lib;d:/starbuck20/samples/DJDBC_LookUp/Debug
mnguyen
8000
Michaels
Devlin
-->
- From the File menu of the editor window for DJDBC_Lookup.stm, click Save to Database to save
this template into the database
- Close DJDBC_Lookup.stm
Client Side Instructions
To run this sample from SQL Central
- Start the SQL Anywhere database by clicking on the Start button on your Windows desktop, choosing
Run and then typing in the following command (or by typing in the following at the command line in a
DOS box):
dbeng50 db_name
where db_name is the path to your SQL Anywhere database
For example: dbeng50 d:\sqlany50\sademo.db
- Start the Open Server Gateway for NT by typing in the following at the command line in a DOS box:
dbos50 -v server_name
where server_name is the Open Server Gateway name for your
SQL Anywhere database. (The -v switch is for verbose mode.)
For example: dbos50 -v sademo
- Start SQL Central
- In the main SQL Central window, click on the Site folder to move to \Site.
- Use the right button to click on the DJDBC_Lookup.stm icon and choose View Output or Browse
Output
- Stop the Open Server Gateway for NT by typing in the following at the command line in a DOS box:
dbosstop -S server_name -U userID -P password -x thx1138
where server_name is the Open Server Gateway name
for your SQL Anywhere database
userID is the user Id for the SQL Anywhere database
password is the password for the SQL Anywhere database
For example: dbosstop -S sademo -U dba -P sql -x thx1138
To run this sample from a browser with Dynamo Personal Web Server
- Start the SQL Anywhere database by clicking on the Start button on your Windows desktop, choosing
Run and then typing in the following command (or by typing in the following at the command line in a
DOS box):
dbeng50 db_name
where db_name is the path to your SQL Anywhere database
For example: dbeng50 d:\sqlany50\sademo.db
- Start the Open Server Gateway for NT by typing in the following at the command line in a DOS box:
dbos50 -v server_name
where server_name is the Open Server Gateway name for your
SQL Anywhere database. (The -v switch is for verbose mode.)
For example: dbos50 -v sademo
- Start the Dynamo Personal Web Server
- Start your Web browser and type in the following URL:
http://localhost/Site/DJDBC_LookUp.stm
- Stop the Open Server Gateway for NT by typing in the following at the command line in a DOS box:
dbosstop -S server_name -U userID -P password -x thx1138
where server_name is the Open Server Gateway name
for your SQL Anywhere database
userID is the user Id for the SQL Anywhere database
password is the password for the SQL Anywhere database
For example: dbosstop -S sademo -U dba -P sql -x thx1138