Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in August and this forum will be retired.


I successfully installed SQL Anywhere 17 on a Linux environment. I am able to connect to it with various client applications, using the jconn4.jar driver. However, I have been directed by the customer to use the sajdbc4.jar driver, and I am running into problem.

I developed a simple Java application to try and figure out what I'm doing wrong; I have the source file below.

I run it from the command line like this:

$ java -classpath .:./sajdbc4.jar -Djava.library.path=/opt/sqlanywhere17/lib64 DriverTest

I get the following error:

Connecting to database... java.sql.SQLException: Invalid ODBC handle at sap.jdbc4.sqlanywhere.IDriver.makeODBCConnection(Native Method) at sap.jdbc4.sqlanywhere.IDriver.connect( at java.sql.DriverManager.getConnection( at java.sql.DriverManager.getConnection( at DriverTest.main(

Line 26 corresponds to the line where I'm calling the DriverManager.getConnection method.

I've tried various combinations of JDBC URL values, and I have made sure that all the shared libraries that sajdbc4.jar needs are indeed in the /opt/sqlanywhere17/lib64 DriverTest folder.

Any ideas as to how I can solve this problem?

thanks, Gonzalo

import java.sql.*;

public class DriverTest {

static final String JDBC_DRIVER = "sap.jdbc4.sqlanywhere.IDriver";

//static final String DB_URL = "jdbc:sqlanywhere:uid=DBA;pwd=sql;links=tcpip(host=;eng=demo;port=2638";
static final String DB_URL = "jdbc:sqlanywhere:links=tcpip(host=;eng=demo;port=2638";
//static final String DB_URL = "jdbc:sqlanywhere:ServerName=localhost;eng=demo;port=2638";
//static final String DB_URL = "jdbc:sqlanywhere:uid=DBA;pwd=sql;eng=demo;port=2638";

//static final String DB_URL = "jdbc:sqlanywhere:UserID=DBA;Password=sql;eng=demo;host=localhost;port=2638";

static final String USER = "DBA";
static final String PASS = "sql";

public static void main(String[] args) {
    Connection conn = null;
    Statement stmt = null;
    try {

        System.out.println("Connecting to database...");
        conn = DriverManager.getConnection(DB_URL, USER, PASS);
        //conn = DriverManager.getConnection(DB_URL);

        System.out.println("Creating statement...");
        stmt = conn.createStatement();
        String sql;
        sql = "SELECT PersonId, LastName, FirstName, Address, City FROM Persons";
        ResultSet rs = stmt.executeQuery(sql);

        while ( {
            int id  = rs.getInt("PersonId");
            String lastName = rs.getString("LastName");
            String firstName = rs.getString("FirstName");
            String address = rs.getString("Address");
            String city = rs.getString("City");

            System.out.print("ID: " + id);
            System.out.print(", Last Name: " + lastName);
            System.out.print(", First Name: " + firstName);
            System.out.println(", Address: " + address);
            System.out.println(", City: " + city);
    } catch (SQLException se) {
    } catch (Exception e) {
    } finally {
        try {
            if (stmt != null)
        } catch (SQLException se2) {
        }// nothing we can do
        try {
            if (conn != null)
        } catch (SQLException se) {


asked 12 Aug '16, 14:21

gdmoreno_sqla's gravatar image

accept rate: 100%

There is a discussion about this happening under Windows at Don't know if it will be helpful to you or not.

(12 Aug '16, 18:18) Terry Wilkinson


I had to set an environment variable called LD_LIBRARY_PATH, and have it point to the directory with the shared libraries for SQL Anywhere 17. Using the java.library.path JVM parameter wasn't right.

So I was able to run it like this:

$ export LD_LIBRARY_PATH=/opt/sqlanywhere17/bin64

$ java -classpath .:./sajdbc4.jar DriverTest

thanks, Gonzalo

permanent link

answered 17 Aug '16, 19:20

gdmoreno_sqla's gravatar image

accept rate: 100%

This should help you out.


How to Load the SQL Anywhere JDBC 4.0 Driver

Ensure that the SQL Anywhere JDBC 4.0 driver is in your class file path.

set classpath=%IQDIR%\java\sajdbc4.jar;%classpath%

The JDBC 4.0 driver takes advantage of the new automatic JDBC driver registration. The driver is automatically loaded at execution startup when it is in the class file path. Required Files

The Java component of the SQL Anywhere JDBC 4.0 driver is included in the sajdbc4.jar file installed into the Java subdirectory of your SAP Sybase IQ installation. For Windows, the native component is dbjdbc16.dll in the bin32 or bin64 subdirectory of your SAP Sybase IQ installation; for Unix, the native component is This component must be in the system path.

permanent link

answered 15 Aug '16, 09:59

BillyB's gravatar image

accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 12 Aug '16, 14:21

question was seen: 5,341 times

last updated: 17 Aug '16, 19:20