
I originally posted this a few years ago to help people configure their Java applications to use the iAnywhere JDBC driver, which was replaced by the SQL Anywhere JDBC driver in SQL Anywhere version 12. I am reposting it here with a few minor updates, since I still refer to it occasionally and I think it is still useful.
I have heard from customers that connecting to SQL Anywhereover JDBC can be difficult at times. In my investigations of this, I have found that this is almost always due to confusion over the classname to use to register the JDBC driver, and the URL's to use to actually connect to the database. In stepping back, I can see how people might easily get confused based on the history of the JDBC driver. Here is my attempt to clarify things by following the history of the driver, starting with SQL Anywhere version 9.
Before I go into detail on the history of the SQL Anywhere JDBC driver, here is a table which explains classpath settings, jar files required, driver name URLs and sample connection URLs.
SQL Anywhere Version | JDBC jar file to include in classpath | Driver classname | Connection URL |
---|---|---|---|
9.0.2 | %ASA90%\java\jodbc.jar | ianywhere.ml.jdbcodbc.IDriver | jdbc:odbc:Driver=Adaptive Server Anywhere 9.0;UID=DBA;PWD=sql;eng=demo |
10.0.0 | %SQLANY10%\java\jodbc.jar | ianywhere.ml.jdbcodbc.jdbc3.IDriver | jdbc:odbc:Driver=SQL Anywhere 10 Demo;UID=DBA;PWD=sql;eng=demo |
10.0.1 | %SQLANY10%\java\jodbc.jar | ianywhere.ml.jdbcodbc.jdbc3.IDriver | jdbc:ianywhere:Driver=SQL Anywhere 10;DSN= SQL Anywhere 10 Sample |
11.0.0 | %SQLANY11%\java\jodbc.jar | ianywhere.ml.jdbcodbc.jdbc3.IDriver | jdbc:ianywhere:Driver=SQL Anywhere 10;DSN= SQL Anywhere 11 Sample |
11.0.1 | %SQLANY11%\java\sajdbc.jar | sybase.jdbc.sqlanywhere.IDriver | jdbc:sqlanywhere:uid=DBA;pwd=sql;eng=demo |
12.0.0 | %SQLANY12%\java\sajdbc4.jar | no longer required for JDBC 4.0 | jdbc:sqlanywhere:uid=DBA;pwd=sql;eng=demo |
16.0 | %SQLANY16%\java\sajdbc4.jar | no longer required for JDBC 4.0 | jdbc:sqlanywhere:uid=DBA;pwd=sql;eng=demo |
DriverManager.registerDriver(
(Driver)Class.forName( "ianywhere.ml.jdbcodbc.IDriver" ).newInstance() );
Since the iAnywhere JDBC/ODBC driver is a bridge driver, to connect to your SQL Anywhere database, you need to specify a "DRIVER=" parameter along with the rest of your connect string. For example:Connection con = DriverManager.getConnection(
"jdbc:odbc:Driver=Adaptive Server Anywhere 9.0;UID=DBA;PWD=sql;eng=demo" );
or, you could use an ODBC data source like this:Connection con = DriverManager.getConnection(
"jdbc:odbc:DSN= Adaptive Server Anywhere 9.0 Sample" );
DriverManager.registerDriver(
(Driver)Class.forName( "ianywhere.ml.jdbcodbc.jdbc3.IDriver" ).newInstance() );
Once registered, the connection URL was the same as in verison 9, above.Connection con = DriverManager.getConnection(
"jdbc:ianywhere:Driver=SQL Anywhere 10;DSN= SQL Anywhere 10 Sample" );
The "jdbc:ianywhere" portion of the connection string was actually back-ported to a 9.0.1 ebf, so if you are running one of the later 9.0.1 or 9.0.2 ebfs, the above connection URL will work for you as well.DriverManager.registerDriver(
(Driver) Class.forName( "sybase.jdbc.sqlanywhere.IDriver" ).newInstance() );
Then, to connect, you use the following URL:Connection con = DriverManager.getConnection(
"jdbc:sqlanywhere:uid=DBA;pwd=sql;eng=demo" );
Connection con = DriverManager.getConnection(
"jdbc:sqlanywhere:uid=DBA;pwd=sql;eng=demo" );
That concludes our history lesson. Confused yet?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
12 | |
7 | |
7 | |
7 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 |