Sybase JDBC Driver Sample Program


 

The Sybase JDBC Driver Sample is a Java application that will demonstrate the use of the Sybase JDBC Driver to connect to either a SQL Server or a SQL Anywhere database using the Sybase TDS protocol.

 

Installation Instructions

To run this sample on your machine, you will need to install the following components:

 

SQL Server Database

To connect to a SQL Server Database

  1. Go to the "Jato Samples"\Sybase_JDBC_Driver\Debug subfolder of your Jato installation folder.
  2. Run the Java application sample using a Java interpreter.
        For example: jview Sybase_JDBC_Driver
  3. Fill in the connection information for the SQL Server database that you want to connect to.
        Host refers to the host name
        Port refers to the port number
        Database refers to database on the SQL Server
        User ID refers to the User Id
        Password refers to the Password
    
        For example:
            Host     = mnguyen
            Port     = 5000
            Database = pubs2
            UserID   = sa
            Password =
  4. Click on SQL Server Database
  5. Click on the Query box and type in your query.
        For example: select * from authors
  6. Click on Get Query

 

SQL Anywhere Database

To configure the Open Server Gateway for a SQL Anywhere Database

  1. Install the Open Server Gateway components (SQL Anywhere Open Server Gateway and Sybase Open Server components) when installing SQL Anywhere Server.
  2. 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 
  3. Run \sybase\bin\sqledit.exe to provide an Open Server Gateway name for your SQL Anywhere database and configure your connection profile.
  4. 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 
  5. Click on Add to add this name to the list of Server Entries.
  6. From the Service Type list, select query to add a query service
  7. From the Platform list, select the appropriate platform (NT, dos, or win3).
  8. From the Net-Library Driver list, select NLWNSCK. This is the WinSock network-library driver.
  9. 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 
  10. Click Add Service to add this query service.
  11. From the Service Type list, select master to add a master service
  12. Repeat Steps 7, 8 and 9.
  13. 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:

To connect to a SQL Anywhere Database

  1. 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 
  2. 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 
  3. Go to the "Jato Samples"\Sybase_JDBC_Driver\Debug subfolder of your Jato installation folder.
  4. Run the Java application sample using a Java interpreter.
        For example: jview Sybase_JDBC_Driver
  5. Fill in the connection information for the SQL Anywhere database that you want to connect to.
        Host refers to the host name
        Port refers to the port number
        User ID refers to the User Id
        Password refers to the Password
        NOTE: Database does not apply when connecting to SQL Anywhere
    
        For example:
            Host     = mnguyen
            Port     = 8000
            UserID   = dba
            Password = sql
  6. Click on the Query box and type in your query.
        For example: select * from product
  7. Click on Get Query
  8. 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 

D