3

Scenario: I have installed a 32-bit ODBC driver to connect to database A, and a 64-bit ODBC driver to database B.

I know that I can connect to a 32-bit ODBC driver in java x86 and to a 64-bit ODBC driver in java x64, but what if I need to use a 64-bit ODBC driver and a 32-bit ODBC driver in the same Java application?

Can I connect to both a 32-bit ODBC driver and a 64-bit ODBC driver in Java?

I'm very curious about it.

TallTed
  • 9,069
  • 2
  • 22
  • 37
AndreaTaroni86
  • 549
  • 12
  • 27
  • Your question is a bit unclear, and should be reworded to correct/clarify. "ODBC:JDBC" suggests you're trying to make an ODBC client application connect through a JDBC driver (via ODBC-to-JDBC Bridge), but everything else you've said suggests you're really trying to do is make a Java JDBC app connect through a couple of ODBC drivers (via JDBC-to-ODBC Bridge). – TallTed Nov 18 '16 at 15:06

2 Answers2

3

Can I connect to a 32-bit ODBC:JDBC and both to a 64-bit ODBC:JDBC in java?

No. You cannot. It is not possible to invoke 32-bit native code from a 64-bit JVM. However, ODBC should be ODBC - if you have a 64-bit ODBC:JDBC driver then it should work to connect from 64-bit Java.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • As a follow up to this answer, OP should take a look at [this](http://stackoverflow.com/questions/10289655/how-to-connect-to-a-32-bit-access-database-from-64-bit-jvm). It's not possible to connect to a 32-bit ODBC via a 64-bit Java application as you've mentioned already. – px06 Nov 18 '16 at 10:51
  • None of this is quite accurate. See my answer. – TallTed Nov 18 '16 at 21:18
  • @TallTed Technically, this is completely accurate. You are calling a second JVM to act as a bridge; thus you still require a 32-bit JVM (or at least a 32-bit ODBC driver and a some sort of host) to run the 32-bit native code. – Elliott Frisch Nov 18 '16 at 23:03
  • I am not calling a second JVM. You're correct that it's not possible to make a Type 1 JDBC connection from a 32-bit JVM to a 64-bit ODBC driver, nor from a 64-bit JVM to a 32-bit ODBC driver — but both of these can be made as Type 3 JDBC connections. OP did not ask, "Can I make _a **Type 1** JDBC connection_ to both 32-bit and 64-bit ODBC drivers from either 32-bit or 64-bit JVM?" She asked "Can I make _**a JDBC connection**_ to both ...?" – TallTed Nov 19 '16 at 00:04
  • @TallTed OP's question was *what if I need to use a 64 bit driver and a 32 bit driver in the same application?* In n-tier design, each tier is an independent application. I would prefer the database's type-4 JDBC driver over a ODBC bridge. Or an ETL process if that simply isn't possible. – Elliott Frisch Nov 19 '16 at 00:53
0

Yes, you can

  • use a 64-bit ODBC driver from a 32-bit JVM
  • use a 32-bit ODBC driver from a 64-bit JVM
  • simultaneously use a 64-bit ODBC driver and a 32-bit ODBC driver from the same Java application, in either a 32-bit or 64-bit JVM

You just need to use a Type 3 JDBC connection -- a "multi-tier" JDBC-to-ODBC Bridge -- such as the Enterprise Edition JDBC Driver for ODBC Data Sources from my employer, to bridge the "bitness" gap.

A Type 3 JDBC-to-ODBC connection puts a "pure Java" JDBC Driver in the JVM with your Java app, and this communicates via TCP/IP with some C-based ODBC Client components that go in the "native" OS environment with the ODBC driver(s) -- which need not be on the same host as each other, and neither need be on the same host as the JVM.

Type 3 JDBC Driver in 32-bit JVM
   -> ... TCP/IP ... 
      -> 64-bit ODBC Bridge Middleware
         -> 64-bit ODBC Driver 

or

Type 3 JDBC Driver in 64-bit JVM
   -> ... TCP/IP ... 
      -> 32-bit ODBC Bridge Middleware
         -> 32-bit ODBC Driver 

You may choose to use a Type 1 "single-tier" JDBC-to-ODBC Bridge such as the Lite Edition JDBC Driver for ODBC Data Sources from my employer that matches the bitness of the JVM and one ODBC driver (let's say 64-bit, here), and use the "multi-tier" JDBC-to-ODBC Bridge only for the other (32-bit) ODBC driver. Remember that Java 8 and later no longer include the Sun JDBC-to-ODBC Bridge (classname sun.jdbc.odbc.JdbcOdbcDriver, used jdbc:odbc:<dsn>;UID=<uid>;PWD=<pwd> URLs) in the JVM.

Community
  • 1
  • 1
TallTed
  • 9,069
  • 2
  • 22
  • 37