The forum will experience an outage sometime between February 10 at 7:00pm EST and February 12 at 11:59 EST for installation of security updates. The actual time and duration of the outage are unknown but attempts will be made to minimize the downtime. We apologize for any inconvenience.

Hi,

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(IDriver.java:809) at java.sql.DriverManager.getConnection(DriverManager.java:571) at java.sql.DriverManager.getConnection(DriverManager.java:215) at DriverTest.main(DriverTest.java:26)

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=127.0.0.1);eng=demo;port=2638";
static final String DB_URL = "jdbc:sqlanywhere:links=tcpip(host=127.0.0.1);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 {
        Class.forName(JDBC_DRIVER);

        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 (rs.next()) {
            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);
        }
        rs.close();
        stmt.close();
        conn.close();
    } catch (SQLException se) {
        se.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (stmt != null)
                stmt.close();
        } catch (SQLException se2) {
        }// nothing we can do
        try {
            if (conn != null)
                conn.close();
        } catch (SQLException se) {
            se.printStackTrace();
        }
    }
    System.out.println("Goodbye!");
}

}

asked 12 Aug '16, 14:21

gdmoreno_sqla's gravatar image

gdmoreno_sqla
5615
accept rate: 0%

There is a discussion about this happening under Windows at http://sqlanywhere-forum.sap.com/questions/16238/error-connecting-remotely-using-sajdbc4jar. Don't know if it will be helpful to you or not.

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

Folks,

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

gdmoreno_sqla
5615
accept rate: 0%

This should help you out. http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc01776.1600/doc/html/san1357754912147.html

Billy

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 libdbjdbc16.so. This component must be in the system path.

permanent link

answered 15 Aug '16, 09:59

BillyB's gravatar image

BillyB
261
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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×64
×8

question asked: 12 Aug '16, 14:21

question was seen: 250 times

last updated: 17 Aug '16, 19:20