How the Connection Example Works

The external connection example is a Java command line program.

Importing Packages

The application requires a couple of packages, which are imported in the first lines of JDBCConnect.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, JDBCConnect.main is the only public method in the application.

The JDBCConnect.main method carries out the following tasks:

  1. Determines which driver to load based on the command line argument. The SQL Anywhere JDBC 4.0 and jConnect 7.0 drivers are automatically loaded at startup if they are in the class file path.

  2. Connects to the default running database using the selected JDBC driver URL. The getConnection method establishes a connection using the specified URL.

  3. Creates a statement object, which is the container for the SQL statement.

  4. Creates a result set object by executing a SQL query.

  5. Iterates through the result set, printing the column information.

  6. Closes each of the result set, statement, and connection objects.