JDBC driver vs Bridge

I have used JDBC in several applications now to query Derby, PostgreSQL and now MySQL databases. I guess I'm choking on some basic terminology, trying to understand what is really happening under the hood. A few terms that I saw doubted:

  • ODBC
  • Jdbc driver
  • Bridge
  • JDBC-ODBC Bridge

For each of them, I did my best to do digging and understand what they represent, what they do and how they relate to each other. I believe that I’m about 70% of the way, I just can’t find anything (articesl, blogs, documents, etc.) that connect everything well together and confirm my suspicions.

ODBC seems to be a C library (perhaps a DLL?) That programs can use to communicate with RDBM systems (such as PostgreSQL and MySQL). All requests to these systems enter this library and exit it in this system.

The JDBC-ODBC bridge is a Java component that contains native code that allows JDBC to communicate with this ODBC library on this system.

JDBC is the pure Java API for querying RDBM systems.

The JDBC driver (such as the PostgreSQL-JDBC driver) is where I really am having problems. . If all RDBM systems follow RDBMS standards and can communicate with the ODBC library, then why does JDBC need different “drivers” for each of them?

What are these drivers? What are they doing? Why are they needed? Also clarification on any other statements I made here would be greatly appreciated. Thanks in advance!

+4
source share
5 answers

You are almost there. Good question.

What are these drivers. . A pure JDBC driver is a driver written in Java that does not require an ODBC driver. You should only use ODBC drivers (via the JDBC-ODBC bridge) if you do not have a direct JDBC driver for your database (which is extremely rare, since most (if not all) databases support JDBC at the moment).

Pure JDBC has the advantage of not requiring ODBC. ODBC is usually difficult to configure and requires that you have your own client database library installed (for example, Oracle OCI or Sybase CT Library).

It used to be that ODBC or native drivers were chosen for performance reasons, but I think that today pure Java / JDBC works almost as well as their native / ODBC counterparts.

What they do : same as ODBC. Standardized Java API for accessing relational databases.

Why are they needed ? They are necessary because it’s easier to work with them, you just need the JAR JAR library and your URL connection. Contrary: built-in client library + ODBC driver + JDBC-ODBC configuration. This is also the case when each individual database has its own network protocol for querying it and for obtaining results. Therefore, you need one driver for each database provider. Each of them implements a specific protocol, which he needs to connect to his relational database manager. If you were in a world where the entire database shared the same SQL language and the same communication protocol, you would need only one driver. But this will not happen soon.

+6
source

ODBC and JDBC are equivalent. They both use drivers to convert ODBC (or JDBC) calls into their own database commands. ODBC is older and written in C / C ++, and JDBC is written in Java. When JDBC came out, there were no JDBC drivers for most databases, so they created a JDBC-ODBC driver to allow people to use the already available ODBC drivers. This is rarely used now, since almost every database has a pure Java JDBC driver

+5
source

Just because DBs use "standard" SQL (and this is in quotation marks for some reason) does not mean that the DB uses the same low-level protocol for communication. SQL is just syntax, but not protocol.

The protocols for Postgres and, say, Oracle, are completely different and offer different functions, although both of them use similar SQL functions.

SQL itself, being standard, has large deviations in implementations. For example, MySQL is notorious for being less SQL compatible than other databases. While many of the SQLs used today are portable across the database, there are many.

JDBC and ODBC are kindred spirits. They provide a common interface that your application can use to communicate with RDBS. They also provided a common model for suppliers. These are the drivers.

Suppliers implement a driver that allows a JDBC / ODBC compatible program to talk to their database. The driver task converts ODBC / JDBC calls to the corresponding SQL queries or other management calls for the database.

JDBC / ODBC Bridge is a JDBC driver that speaks to an existing ODBC driver. This is an abomination. Do not use it. Every database today has JDBC drivers. And stick with type 4 JDBC drivers, if at all possible, as they are native Java, not type 2 drivers that use JNI for binary. Type 4 buggy drivers provide exceptions, type 2 buggy drivers lead to JVM crashes that destroy your application server. No thanks.

+1
source

You're right; You are very close to the full picture!

JDBC and ODBC are conceptually very similar. Both of them are the basis for interacting with databases. JDBC is specific to Java, and ODBC is specific to Windows. However, both JDBC and ODBC are actually toothless APIs. In Java terminology, JDBC is actually a collection of unrealized interfaces. Although they define a behavioral contract, they essentially do not know how to talk to any particular database. This is where drivers come in.

Tell us more about JDBC here. JDBC drivers are specific implementations of JDBC interfaces that actually know how to talk to the underlying database engine. JDBC ensures that the ResultSet from the MySQL JDBC driver behaves the same as the ResultSet from the Postgres JDBC driver.

As others have noted, the JDBC / ODBC bridge is just the glue to make code written for JDBC to work with the ODBC infrastructure. As a rule, this only makes sense if you know for sure that you write Java for Windows exclusively; ODBC is Windows-specific, but JDBC is (theoretically) cross-platform.

+1
source
  • Jdbc is a java method for connecting to a database using dricers written in java (with JDBC4).
  • ODBC is the MS Windows way to connect to the database, these drivers are usually written in C
  • The JDBC-ODBC bridge is quite old, in the early days of Java, not all drivers in the JDBC version are available, so building a common bridge between JDBC and existing ODBC drivers.
0
source

Source: https://habr.com/ru/post/1380822/


All Articles