我们可以只用java来使用odbc来连接数据库吗?
我们是否总是必须使用 jdbc 和 Java 程序来连接数据库,或者我们可以仅使用 odbc 来通过 Java 程序连接到数据库吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Sun JRE 包含内置的 JDBC/ODBC 驱动程序 (sun.jdbc.odbc.JdbcOdbcDriver)。以下是如何使用它的示例: http://www.javacoffeebreak.com/articles/jdbc/
该驱动程序已在 Oracle JRE 8 中删除,因此请使用 Java 版本 7 或更早版本。
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.
您不能直接使用ODBC,因为您的JAVA程序需要使用JDBC驱动程序与数据库交互。
You can't use ODBC directly because your JAVA program needs to use the JDBC driver to interact with the Database.
正如其他人提到的,您可以使用 JDBC/ODBC 桥驱动程序。 (在这里重复@Rustam的链接:http://www.javacoffeebreak.com/articles/jdbc/)。
使用 JDBC-ODBC 桥时需要记住以下几点。首先:由于各种原因,Sun 不推荐使用它。使用桥而不是适当的 JDBC 驱动程序的三大影响是:
也就是说,JDBC/ODBC 驱动程序适用于没有直接 JDBC 支持的数据库(大多数主要数据库都支持)。有时您不需要所有这些花哨的功能,只是想快速地将一些东西组合在一起。 JDBC/ODBC 驱动程序就是为此而设计的。
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.
简短的回答:不。
ODBC(开放数据库连接)隐藏了您正在交谈的数据库的详细信息。它与Java无关。如果java程序需要与数据库对话,那么它们必须与ODBC驱动程序交互。要与 ODBC 驱动程序交互,您需要 JDBC-ODBC 驱动程序,它隐藏了通信发生方式的详细信息。您几乎可以进行一些方法调用,然后一切准备就绪。抽象的力量。
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.
您可以使用 JDBC-ODBC 驱动程序
You can use JDBC-ODBC drivers
我的理解是你不会想要——当事情进展不顺利时,它会变得乏味且容易出错。
IE 中,当/如果您从 java 内部调用非 java DLL 时,您无法捕获异常。
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.