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

SQL Anywhere 11.0.1 (Français) » SQL Anywhere Server - Programming » SQL Anywhere Data Access APIs » SQL Anywhere JDBC driver » Connecting from a JDBC client application » Establishing a connection from a server-side JDBC class


Server-side connection example code

The following is the source code for the server-side connection example. It is a modified version of the source code in samples-dir\SQLAnywhere\JDBC\

import java.sql.*;

public class JDBCConnect2
  public static void main( String args[] )
      // Open the connection. May throw a SQLException.
      Connection con = DriverManager.getConnection(
          "jdbc:default:connection" );

      // Create a statement object, the container for the SQL
      // statement. May throw a SQLException.
      Statement stmt = con.createStatement();
      // Create a result set object by executing the query.
      // May throw a SQLException.
      ResultSet rs = stmt.executeQuery(
        "SELECT ID, GivenName, Surname FROM Customers");

      // Process the result set.
      while (
        int value = rs.getInt(1);
        String FirstName = rs.getString(2);
        String LastName = rs.getString(3);
        System.out.println(value+" "+FirstName+" "+LastName);
    catch (SQLException sqe)
      System.out.println("Unexpected exception : " +
                sqe.toString() + ", sqlstate = " +
    catch (Exception e)