cancel
Showing results for 
Search instead for 
Did you mean: 

Connection to ASA from java with jdbc

Former Member
0 Kudos
5,864

I should Ubuntu (x32), java 1.7, there is a library sajdbc4.jar with which you can connect to the database. The problem is that when I declare

Class.forName ("sybase.jdbc4.sqlanywhere.IDriver");

cursing the lack of compiler library libdbjdbc12.so I looked java.library.path in a folder, which was empty, unloaded all the libraries that have been bundled with the distribution sybase, now he swears by the other:

Exception in thread "main" java.lang.UnsatisfiedLinkError: / usr/java/packages/lib/i386/libdbjdbc12.so.1: libdbtasks12_r.so: can not open shared object file: No such file or directory

Although this library is next to libdbjdbc12.so.1

What should be done for her to see him all the necessary libraries?

UPD1: there are also other drivers :), took to try them (jtds, jconn4) ... eventually ran into the wrong username / password to the server, driver is worked. My server on cp1251, and the connection is with ubuntu, which means UTF8.

/ / for jconn4
     Class.forName ("com.sybase.jdbc4.jdbc.SybDriver"). NewInstance ());
     String userUTF8 = "db", pswdUTF8 = "sql", dburlUTF8 = "jdbc: sybase: Tds: 192.168.1.1:5344 / testdb";
     String userCP1251 = new String (userUTF8.getBytes ("UTF-8"), "Cp1251");
     String pswdCP1251 = new String (pswdUTF8.getBytes ("UTF-8"), "Cp1251");
     String dburlCP1251 = new String (dburlUTF8.getBytes ("UTF-8"), "Cp1251");
     / / System.out.println (dburlCP1251 + "" + userCP1251 + "" + pswdCP1251);
     Connection con = DriverManager.getConnection (dburlCP1251, userCP1251, pswdCP1251);

/ / for jtds
     Class.forName ("net.sourceforge.jtds.jdbc.Driver"). NewInstance ());
     String userUTF8 = "db", pswdUTF8 = "sql", dburlUTF8 = "jdbc: jtds: sybase 😕 / 192.168.1.1:5344 / testdb";
     String userCP1251 = new String (userUTF8.getBytes ("UTF-8"), "Cp1251");
     String pswdCP1251 = new String (pswdUTF8.getBytes ("UTF-8"), "Cp1251");
     String dburlCP1251 = new String (dburlUTF8.getBytes ("UTF-8"), "Cp1251");
     / / System.out.println (dburlCP1251 + "" + userCP1251 + "" + pswdCP1251);
     Connection con = DriverManager.getConnection (dburlCP1251, userCP1251, pswdCP1251);

Such are the result of error:

/ / for jconn4
Exception in thread "main" java.sql.SQLException: JZ00L: Login failed. Examine the SQLWarnings chained to this exception for the reason (s).
/ / for jtds
Exception in thread "main" java.sql.SQLException: Login failed

Accepted Solutions (1)

Accepted Solutions (1)

jeff_albion
Advisor
Advisor

If you're using SAJDBC (sajbc4.jar), on Linux / UNIX, libdbtasks12_r.so is loaded from the LD_LIBRARY_PATH environment variable (which translates out to the java.library.path value inside the JVM).

Generally, LD_LIBRARY_PATH is specified by sourcing the provided sa_config.(c)sh for your environment before launching Java. What is this value set to for this Java environment?


Also, SQL Anywhere does not support the use of the jTDS driver. Only jConnect and the SAJDBC driver are supported.


If you're using "jconn4.jar" (jConnect), then your URL should have a jConnect URL format:

Connection con = DriverManager.getConnection("jdbc:sybase:Tds:localhost:2638?ServiceName=DatabaseName", "DBA", "sql");
Former Member
0 Kudos
  1. does not work
  2. a great magic, IT'S ALIVE !! ))

Answers (1)

Answers (1)

Former Member

First, since Java 6 released (JDK 1.6 or later), you don't need to load drivers using the Class.forName() method. The drivers are loaded automatically when the JAR file is recognized by the classloader. (About time, right? No more specifying a class name, making your code less dependent on the vendor JDBC JAR file.)

Now, to answer your question, you will need to specify the java.library.path property. Once you point this at the correct directory, the system should do the rest of the work for you.

If you specified the default directory during installation, the property would point to /opt/sqlanywhere12/libXX (where XX is 32 or 64, depending on your architecture).

You can set up this property in the Java command line. It would look something like this:

java -Djava.library.path=/opt/sqlanywhere12/lib64

Finally, your connection URL is bad. For the SQLAnywhere JDBC driver (the one in sajdbc4.jar), the URL should look like this:

jdbc:sqlanywhere:uid=XXX;pwd=YYY;links=tcpip(host=ZZ.ZZ.ZZ.ZZ);eng=ENGINE
Former Member
0 Kudos

Did as you wrote, it does not work. Driver is not loaded.