Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » SQL Anywhere Server - Programming » SQL Anywhere JDBC API » Connecting from a JDBC client application

Connecting from a JDBC client application Next Page

How the connection example works

The external connection example is a Java command line application.

Importing packages

The application requires a couple of packages, which are imported in the first lines of

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. Loads the iAnywhere JDBC driver. To load the jConnect 6.0.5 JDBC driver instead, use the driver string "com.sybase.jdbc3.jdbc.SybDriver" (as shown in comments).

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

  2. Connects to the default running database using an iAnywhere JDBC driver URL. If you are using the jConnect driver instead, use the URL "jdbc:sybase:Tds:localhost:2638" (as shown in comments) with "DBA" and "sql" as the user ID and password, respectively.

    DriverManager.getConnection 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.