cancel
Showing results for 
Search instead for 
Did you mean: 

JDBC driver and connecting to a DSN

Former Member
3,734

I've written a JDBC application that connects to a ODBC DSN. The local Sybase 10 system DSN called TEST connects to a running Sybase database server using TCP. When tested the DSN connects to the remote server successfully

On the local system DBISQL -c "DSN=TEST;USERID=dba;password=password" also connects fine

But when I attempt to connect to the local DSN using JDBC code below I get error [Sybase][ODBC Driver][SQL Anywhere]Database server not found)

Class.forName("ianywhere.ml.jdbcodbc.IDriver"); con = DriverManager.getConnection("jdbc:odbc:Driver=SQL Anywhere 10;DSN=TEST;;uid=dba;pwd=password");

If I run the same code on the same PC as the Sybase DB server the jdbc code works fine.

Why can't JDBC connect to local DSNs that connect to remote sybase DB servers?

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member

My guess is that you created the DSN for a specific bitness (i.e. either 32-bit or 64-bit) but the JAVA VM is a different bitness. Trying creating the DSN for both 32-bit and 64-bit binaries.

jack_schueler
Product and Topic Expert
Product and Topic Expert
0 Kudos

Note: Bitness of the DSN only matters if you are creating a SYSTEM DSN (rather than a USER DSN). If it is a SYSTEM DSN that you are trying to set up, then use \\windows\\SysWOW64\\odbcad32.exe to set up the 32-bit SYSTEM DSN.

Breck_Carter
Participant
0 Kudos

Bitness of the DSN only matters if you are creating a SYSTEM DSN (rather than a USER DSN)

Are you 100% sure of that? It differs from my experience.

VolkerBarth
Contributor
0 Kudos

Well, it meets my experience and fits well to John's answer on your older question:

Please explain the ODBC Administrator situation in 64-bit Windows 7

Aside: I just stumbled over this again yesterday...:(

jack_schueler
Product and Topic Expert
Product and Topic Expert
0 Kudos

You can run this at the Command Prompt to check out my claim:

  1. To list 64-bit System DSNs: reg query HKLM\\SOFTWARE\\ODBC\\ODBC.INI /s

  2. To list 32-bit System DSNs: reg query HKLM\\SOFTWARE\\Wow6432Node\\ODBC\\ODBC.INI /s

  3. To list User DSNs: reg query HKCU\\SOFTWARE\\ODBC\\ODBC.INI /s

HKLM is the LOCAL MACHINE hive.

HKCU is the CURRENT USER hive (this hive is bitness-agnostic).

Hence, there is no HKCU\\SOFTWARE\\Wow6432Node\\ODBC\\ODBC.INI.

Where things get really interesting is when you are developing 64-bit applications with Visual Studio. VS design-time is 32-bit (in the version that I use) and run-time is 64-bit. So if you are doing something at design-time that requires the System DSN, then you had better make sure that you have the 32-bit DSN.

Former Member
0 Kudos

If the jvm is 32bit, use windowsSysWOW64odbcad32.exe to set up the 32-bit SYSTEM DSN. Otherwise just create default 64bit SYSTEM DSN.

After create it, please try to test the connection in the odbc manager.

jack_schueler
Product and Topic Expert
Product and Topic Expert
0 Kudos

Have your tried using the iAnywhere JDBC driver. Try something like this ...

        // Open the connection. May throw a SQLException.
        DriverManager.registerDriver( (Driver)
            Class.forName(
            "ianywhere.ml.jdbcodbc.jdbc3.IDriver").newInstance()
            );

        Connection con = DriverManager.getConnection(
            "jdbc:ianywhere:DSN=test" );

If this doesn't work, go to the ODBC administrator and try the Test Connection button for your DSN. If the connection fails, then you haven't set up your DSN correctly.

Ref: http://dcx.sybase.com/index.html#1001/en/dbpgen10/pg-jdbc-s-3454968.html