Sybase JDBC Driver Sample Program

(Client Side)


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 \Debug directory in the 'Sybase_JDBC_Driver' project where the class files are located.
  2. Run the Java application sample using your favourite Java interpreter.
    For example: "java Sybase_JDBC_Driver"
  3. Fill in the connection information for the SQL Server database that you want to connect to.
    For example: "Host = mnguyen, Port=5000, Database=pubs2, UserID=sa, Password="
  4. Click on the check box 'SQL Server Database' to indicate that it is a SQL Server Database that you want to connect to.
  5. Type in your query in the 'Query' text box.
    For example: "select * from authors"
  6. Click on the 'Get Query' button.

 

SQL Anywhere Database

To configure the Open Server Gateway for a SQL Anywhere Database

  1. When installing your SQL Anywhere Server, you must intall the Open Server Gateway components. Therefore, make sure that you install the 'SQL Anywhere Open Server Gateway' and 'Sybase Open Server components'.
  2. Make sure that your SYBASE environment variable is set to point to the directory where you've installed the Open Server Gateway components.
  3. Run 'sqledit.exe' (which should be located under the \sybase directory) to provide an Open Server Gateway name for your SQL Anywhere database and to configure its connection profile.
  4. Add an Open Server Gateway name for your SQL Anywhere database under 'Input Server Name'. The convention is to give it the same name as your SQL Anywhere database. Then click 'Add'.
    For example: "sademo"
  5. To add a Query Service, first click on 'query' on 'Service Type:' under 'Connection Service Entry'.
  6. Click on the appropriate platform on 'Platform:'.
  7. Click on 'NLWNSCK' on 'Net-Library Driver:'.
  8. Under 'Connection Information/Network Address:', type in the machine name where the SQL Anywhere database is located. This typically is the name of the computer that you're currently working on. Then type a comma, followed by the port number where client programs can access this SQL Anywhere database. Here, you can typically choose any unused port number.
    For example: "MNGUYEN, 8000"
  9. Click on the 'Add Service' button to add this query service.
  10. To add a Master Service, click on 'master' on 'Service Type:' under 'Connection Service Entry'.
  11. Repeat Steps 6, 7 and 8.
  12. Save this 'sql.ini' file by choosing 'File' and 'Save'.

To connect to a SQL Anywhere Database

  1. Start the SQL Anywhere database by clicking on your 'Start Button' and 'Run' and typing in the following, or by simply typing in the following at the command line (in a DOS box):
    "dbeng50 db_name", where db_name is the name of your SQL Anywhere database (with path)
    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
    For example: "dbos50 -v sademo"
  3. Go to the \Debug directory in the 'Sybase_JDBC_Driver' project where the class files are located.
  4. Run the Java application sample using your favourite Java interpreter.
    For example: "java Sybase_JDBC_Driver"
  5. Fill in the connection information for the SQL Anywhere database that you want to connect to. Please note that you will have to enter the host name where the SQL Anywhere database resides under 'Host:', not the Open Server Gateway name for the SQL Anywhere database.
    For example: "Host = mnguyen, Port=8000, Database=, UserID=dba, Password=sql"
  6. Make sure that the check box 'SQL Server Database' is not checked to indicate that you are not connecting to a SQL Server database.
  7. Type in your query in the 'Query' text box.
    For example: "select * from product"
  8. Click on the 'Get Query' button.
  9. To stop the Open Server Gateway for NT, type 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 and password the password for the SQL Anywhere database.
    For example: "dbosstop -S sademo -U dba -P sql -x thx1138"