To connect to a database via the SQL Anywhere JDBC driver, supply a URL for the database.
The following is an example of how to connect to a database.
Connection con = DriverManager.getConnection( "jdbc:sqlanywhere:DSN=SQL Anywhere 17 Demo;Password="+pwd );
The URL contains jdbc:sqlanywhere: followed by a connection string. If the sajdbc4.jar file is in your class file path, then the SQL Anywhere JDBC driver is loaded automatically and handles the URL. As shown in the example, an ODBC data source (DSN) may be specified for convenience, but you can also use explicit connection parameters, separated by semicolons, in addition to or instead of the data source connection parameter.
If you do not use a data source, you must specify all required connection parameters in the connection string:
Connection con = DriverManager.getConnection( "jdbc:sqlanywhere:UserID=DBA;Password=passwd;Start=..." );
The Driver connection parameter is not required since neither the ODBC driver nor ODBC driver manager is used. If present, it is ignored.
The following is another example in which a connection is made to the database SalesDB on the server Acme running on the host computer Elora using TCP/IP port 2638.
Connection con = DriverManager.getConnection( "jdbc:sqlanywhere:UserID=DBA;Password=passwd;Host=Elora:2638;ServerName=Acme;DatabaseName=SalesDB" );