Reputation: 1161
Do we always have to use jdbc with Java programs for making connectivity with database or can we use only odbc for connecting to databases with Java programs?
Upvotes: 11
Views: 22490
Reputation: 85266
Sun JRE contains a built-in JDBC/ODBC driver (sun.jdbc.odbc.JdbcOdbcDriver). Here's an example how to use it: http://www.javacoffeebreak.com/articles/jdbc/
The driver was removed in Oracle JRE 8, so use Java version 7 or earlier.
Upvotes: 5
Reputation: 7025
My understanding is that you would not want to - it would become tedious and error prone when things dont go perfectly.
I.E. you can't catch an exception when/if you invoke a non java DLL from inside java.
Upvotes: 0
Reputation: 5834
Short answer : NO.
ODBC ( Open Database Connectivity ) hides the details of what database you are talking to. It has nothing to do with Java. If java programs need to talk to the database, then they have to interact with ODBC drivers. To interact with ODBC drivers, you need JDBC-ODBC drivers which hides the details of how the communication happens. You can pretty much make a few method calls and all set to go. The power of abstraction.
Upvotes: 1
Reputation: 11463
As others have mentioned you can use the JDBC/ODBC bridge driver. (Repeating @Rustam's link here: http://www.javacoffeebreak.com/articles/jdbc/).
There are a couple things to keep in mind when using the JDBC-ODBC bridge. First: it's use was not recommended by Sun for various reasons. The top three implications of using the bridge instead of a proper JDBC driver are:
That said, the JDBC/ODBC driver will work for a database that does not have direct JDBC support (most major databases do). Sometimes you don't need all those fancy features and just want to throw something together quickly. The JDBC/ODBC driver is designed for that.
Upvotes: 1
Reputation: 74064
You can't use ODBC directly because your JAVA program needs to use the JDBC driver to interact with the Database.
Upvotes: 1