To connect to a database via a SQL Anywhere JDBC driver, you need to supply a URL for the database. For example:
Connection con = DriverManager.getConnection( "jdbc:sqlanywhere:DSN=SQL Anywhere 12 Demo" ); |
The URL contains jdbc:sqlanywhere: followed by a connection string. If the sajdbc4.jar file is in your class file path, then the JDBC 4.0 driver will have been loaded by default and it will handle the URL. Otherwise, the JDBC 3.0 driver will respond to the same URL, provided that it is in the class file path and has been successfully loaded. 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=sql;Start=..." ); |
The Driver connection parameter is not required since neither the ODBC driver nor ODBC driver manager is used. If present, it will be ignored.
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |