什么是JDBC驱动程序的1,2,3或4型? [英] What is type 1,2,3 or 4 of a JDBC Driver?

查看:117
本文介绍了什么是JDBC驱动程序的1,2,3或4型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要使用Java连接数据库,我们大多数人都使用JDBC API。

To connect to a database using Java, most of us use JDBC API.

我们通常在类路径中包含 ojdbc14 (适用于Java 1.4)等驱动程序,在程序中我们使用 Class.forName 使用它。

We normally include driver like ojdbc14 (Intended for Java 1.4) in class path, and in program we use Class.forName to use it.

与大多数其他罐不同,进口不是来自ojdbc14,它们来自 java.sql ,它位于 rt.jar 本身。那么每种驱动器使用哪种类型的驱动器(1,2,3,4)?

Unlike in most other jars the imports are not from ojdbc14, they are from java.sql which is in rt.jar itself. So which type of driver (1,2,3,4) is used for each of these?

推荐答案

您正在使用java.sql类的jdbc接口,因此驱动程序的类型不会对您产生任何逻辑影响代码,它只会影响运行时/部署。

you are using the jdbc interface from java.sql classes, so the type of driver will not have any logic impact in your code, it will only have runtime / deployment impact.

你也在使用Oracle的ojdb14.jar,可能是瘦的jdbc配置,这意味着你是使用type-4驱动程序配置。使用这样的配置,您只需要将JDBC jar文件与数据库访问程序一起部署。

You are also using the ojdb14.jar from Oracle, probably with a "thin" jdbc configuration, which means you are using a type-4 driver configuration. With such a configuration, you will only need to deploy the JDBC jar file with your database accessing program.

其他选项包括JDBC桥,这实际上意味着ODBC连接包裹在JDBC服装中。这意味着您必须配置系统以获得正确的ODBC功能,然后使用JAR文件访问ODBC。由于通过ODBC额外跳数据,人们会认为它比4型访问慢一点;但是,对于特定情况,ODBC有可能在很大程度上进行优化,额外跳可忽略不计。与大多数性能问题一样,通过测试(在您的环境中)发现真相。

The other options include a JDBC bridge, which really means an ODBC connection wrapped in JDBC clothing. This means you would have to configure your system for correct ODBC function, and then use a JAR file to access ODBC. Due to the extra "hop" of data through ODBC, one would expect it to be a bit slower than a type-4 access; however, there is a possibility that the ODBC is optimized to such a great extent for a particular situation, that the extra hop is negligible. As with most performance concerns, the truth is discovered by testing (in your environment).

类型2驱动程序再次使用Java(JDBC)API;但是,它们将调用桥接到C或C ++样式的共享库,然后处理真正的连接。如果驱动程序被优化得如此之快以至于JNI建立/拆除调用的成本可以忽略不计,那么它可能会胜过4类驱动程序。

The type-2 drivers again use a Java (JDBC) API; however, they bridge the calls into a C or C++ style shared library, which then handles the real connection. If the driver is optimized to be so fast that the JNI setup / tear down calls are negligible in cost, then perhaps it might outperform type-4 drivers.

Type 3驱动程序基本上将请求代理(或中继)到另一个网络资源。这通常会导致额外的网络攻击,但同样,这并没有说明实际的性能。

Type 3 drivers basically proxy (or relay) the request to another network resource. That typically incurs an extra network hit, but again, that doesn't say much about actual performance.

类型4驱动程序是你可能想要坚持的。 Java程序直接连接到数据库,这意味着如果出现问题,它将完全在程序的JVM中进行连接(类型1,它在ODBC层中,类型2在本机编译代码中,键入3它在远程网络代理中。)

Type 4 drivers are the ones you probably want to stick with. The Java program connects directly to the database, meaning that if there is a problem, it will be captured entirely within the JVM of the program making the connection (type 1, it's in the ODBC layer, type 2 it's in the native compiled code, type 3 it's in the remote network proxy).

再次,这些都与功能无关;但是,它们都会影响如何部署,如何调试以及如何配置数据库连接。

Again none of this has to do with functionality; however, they all impact how to deploy, how to debug, and how to configure the database connection.

这篇关于什么是JDBC驱动程序的1,2,3或4型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆