我们可以只用java来使用odbc来连接数据库吗?

发布于 2024-10-06 14:49:54 字数 73 浏览 0 评论 0原文

我们是否总是必须使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

鸠书 2024-10-13 14:49:54

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.

﹎☆浅夏丿初晴 2024-10-13 14:49:54

您不能直接使用ODBC,因为您的JAVA程序需要使用JDBC驱动程序与数据库交互。

You can't use ODBC directly because your JAVA program needs to use the JDBC driver to interact with the Database.

枕头说它不想醒 2024-10-13 14:49:54

正如其他人提到的,您可以使用 JDBC/ODBC 桥驱动程序。 (在这里重复@Rustam的链接:http://www.javacoffeebreak.com/articles/jdbc/)。

使用 JDBC-ODBC 桥时需要记住以下几点。首先:由于各种原因,Sun 不推荐使用它。使用桥而不是适当的 JDBC 驱动程序的三大影响是:

  • 并非 JDBC 的所有功能都受支持。 ODBC 是一种限制性更强的 API,因此不支持某些功能(例如事务中的保存点)。但是,最常见的功能(例如准备好的语句)是。
  • 与在 Java 中执行所有操作相比,本机代码到 Java 运行时的转换要慢得多。
  • JDBC/ODBC 驱动程序比相应的 JDBC 驱动程序更脆弱。本质上,如果 ODBC 驱动程序的实现者不以某种方式执行操作,则 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:

  • Not every feature of JDBC is supported. ODBC is a more restrictive API, so some features (like savepoints in transactions) are not supported. However, the most common features like prepared statements are.
  • The native code to Java runtime translation is much slower than if you were doing everything in Java.
  • The JDBC/ODBC driver is more fragile than the appropriate JDBC driver. Essentially, if implementers of the ODBC driver don't do things a certain way, the JDBC driver will fail and throw some extra exceptions you might not be able to catch. In particular, you will be more susceptible to memory leaks. If you aren't building a long running service you might be OK.

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.

虫児飞 2024-10-13 14:49:54

简短的回答:不。

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.

倾城°AllureLove 2024-10-13 14:49:54

我的理解是你不会想要——当事情进展不顺利时,它会变得乏味且容易出错。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文