JDBC   «Prev  Next»
Lesson 5The relationship between JDBC and ODBC
ObjectiveDescribe design considerations for JDBC and ODBC in a solution.

Relationship between JDBC and ODBC

When creating a JDBC and ODBC solution, there are several important design considerations that should be taken into account to ensure the solution is robust, scalable, and secure:
  1. Platform compatibility: JDBC and ODBC drivers should be designed to work across different platforms and operating systems, including compatibility with different versions of the Java and Windows platforms.
  2. Security: The solution should be designed to provide secure connectivity between the application and the database, including support for encryption, authentication, and authorization.
  3. Performance: The solution should be designed to optimize database performance, including minimizing network traffic, optimizing SQL queries, and implementing connection pooling.
  4. Error handling and logging: The solution should be designed to handle errors gracefully, including proper error logging and handling of database exceptions.
  5. Compliance: The solution should be designed to comply with relevant standards, including JDBC and ODBC standards, SQL standards, and any relevant industry-specific standards.
  6. Testing: The solution should be thoroughly tested to ensure that it works correctly and meets the functional and non-functional requirements of the application.
  7. Documentation: The solution should be well-documented, including providing clear documentation for developers on how to use the JDBC and ODBC drivers and API.

Overall, creating a JDBC and ODBC solution requires careful consideration of platform compatibility, security, performance, error handling, compliance, testing, and documentation. By taking these factors into account, developers can ensure that their solution is efficient, secure, and scalable.


JDBC is the preferred choice when using Java

Generally, it's recommended to use JDBC for accessing relational databases from Java applications. Here's why and the limited scenarios where ODBC might be considered:
Why JDBC Is Usually the Better Choice
  • Java-Centric: JDBC (Java Database Connectivity) is specifically designed for Java. It integrates naturally with Java's syntax and paradigms, making database interaction more seamless for Java developers.
  • Performance: JDBC drivers are often optimized for the specific database they connect to, potentially offering better performance than generic ODBC drivers.
  • Platform Independence: While JDBC offers a common API, most databases have platform-specific JDBC drivers, ensuring portability of your code across different operating systems.
  • Wide Support: JDBC is widely adopted and has a rich ecosystem of tools, libraries, and community support within the Java world.

Limited Cases Where ODBC Might Be a Factor
  • Legacy Databases: If you're working with a very old or niche database that only offers an ODBC driver, it may be your only option for accessing it from Java.
  • Mixing Languages: If you have a project combining Java with other languages that rely heavily on ODBC, using ODBC might be considered for consistency, though less ideal from the Java side.
  • Pre-existing ODBC Expertise: If your team has significant ODBC experience and limited Java/JDBC knowledge, there might be a short-term benefit to using ODBC. However, investing in learning JDBC would be a better long-term strategy.

Important Considerations:
  • ODBC Bridges: There's a "JDBC-ODBC bridge" that lets you use JDBC on top of ODBC drivers. This is often a compromise solution and can introduce performance overheads.
  • Driver Availability: Always ensure there's a reliable and up-to-date ODBC driver for your specific database.

In Summary: Choose JDBC for your Java database projects unless you have a very compelling reason to use ODBC. JDBC provides a cleaner, more performant, and better-supported approach for connecting to relational databases from Java.

JDBC is a Java-based tool used to connect Java applications with relational databases and was created at Sun Microsystems (now Oracle) as a base for building interfaces. Since then Oracle has taken over JDBC development with its most recent release of the JDBC API , which can be used to connect directly to a Java-aware DBMS. JDBC is modeled after the ODBC (Open Database Connectivity), specification originally designed and used by Microsoft. ODBC is based on the C language.

JDBC-ODBC bridge

You will need to use a bridge if your database uses an ODBC driver, and you are attempting to connect to it from the Java platform. Think of the bridge as connecting two pieces of land. A JDBC-ODBC bridge will be used for getting your Java-based call across to the ODBC data source. A JDBC-ODBC bridge is included in the Java 2 platform. The JDBC-ODBC bridge is used for a network connection that is not purely Java-based. The relationship between JDBC and ODBC is that JDBC executes the call and ODBC receives the call over the bridge that serves as a combined conduit and translator. As illustrated in the graphic below, you are bridging two sides of a canyon.
  1. On one side there are Java applets and servlets at work in a Java-dominated solution.
  2. On the other side of the canyon is the data source, in this case a non-Java object.

The bridge accepts the JDBC call, translates it to a standard ODBC call, and sends the call to the ODBC data source.


Advantages of using JDBC with ODBC

There are many advantages of using JDBC in the presence of ODBC in a business solution, rather than using the other database products to perform the functions. The main advantage is that the JDBC API provides a direct means of data access for platform-independent applications that are based on the Java programming language. Later in this course, you will learn how to use the JDBC-ODBC bridge when identifying the different types of drivers that involve JDBC and ODBC. The connection created and used by the JDBC-ODBC bridge is invisible to both sides of that connection.
The client program is not aware that ODBC is used, and the database is not aware that JDBC is used. The connection is managed at the JDBC software layer.
In the next lesson, you will learn about SQL's role in database processing.

SEMrush Software