ASA Programming Guide
JDBC Programming
The iAnywhere JDBC driver provides a JDBC driver that has some performance benefits and feature benefits compared to the pure Java jConnect JDBC driver, but which is not a pure-Java solution.
For information on choosing which JDBC driver to use, see Choosing a JDBC driver.
The Java component of the iAnywhere JDBC driver is included in the jodbc.jar file installed into the Java subdirectory of your SQL Anywhere installation. For Windows, the native component is dbjodbc9.dll in the win32 subdirectory of your SQL Anywhere installation; for UNIX and Linux, the native component is dbjodbc9.so. This component must be in the system path. When deploying applications using this driver, you must also deploy the ODBC driver files.
The following code illustrates how to establish a connection using the iAnywhere JDBC driver:
String driver, url; Connection conn; driver="ianywhere.ml.jdbcodbc.IDriver"; url = "jdbc:odbc:dsn=ASA 9.0 Sample"; Class.forName( driver ); conn = DriverManager.getConnection( url );
There are several things to note about this code:
As the classes are loaded using Class.forName
, the package containing the iAnywhere JDBC driver does not have to be imported using import
statements.
jodbc.jar must be in your classpath when you run the application.
The URL contains jdbc:odbc: followed by a standard ODBC connection string. The connection string is commonly an ODBC data source, but you can also use explicit semicolon separated individual connection parameters in addition to or instead of the data source. For more information on the parameters that you can use in a connection string, see Connection parameters.
If you do not use a data source, you should specify the ODBC driver to use by including the driver parameter in your connection string:
url = "jdbc:odbc:"; url += "driver=Adaptive Server Anywhere 9.0;...";
On UNIX the iAnywhere JDBC driver does not use ODBC Unicode bindings or calls and does not carry out character translations. Sending non-ASCII data through the iAnywhere JDBC driver leads to data corruption.
On Windows the iAnywhere JDBC driver does use ODBC Unicode bindings and calls to translate among character sets.