How the external connection example works

The external connection example is a Java command-line application.

Importing packages

The application requires several libraries, which are imported in the first lines of JDBCExamples.java:

The main method

Each Java application requires a class with a method named main, which is the method invoked when the program starts. In this simple example, JDBCExamples.main is the only method in the application.

The JDBCExamples.main method carries out the following tasks:

  1. Processes the command-line argument, using the machine name if supplied. By default, the machine name is localhost, which is appropriate for the personal database server.

  2. Calls the ASAConnect method to establish a connection.

  3. Executes several methods that scroll data to your command line.

The ASAConnect method

The JDBCExamples.ASAConnect method carries out the following tasks:

  1. Connects to the default running database using Sybase jConnect.

    • Class.forName loads jConnect. Using the newInstance method works around issues in some browsers.

    • The StringBuffer statements build up a connection string from the literal strings and the supplied machine name provided on the command line.

    • DriverManager.getConnection establishes a connection using the connection string.

  2. Returns control to the calling method.