JDBC 4.2接口DriverAction和SQLType-示例 [英] JDBC 4.2 Interfaces DriverAction and SQLType - Examples

查看:373
本文介绍了JDBC 4.2接口DriverAction和SQLType-示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到 DriverAction SQLType .

I'm having trouble to find an example of usage of JDBC 4.2 new interfaces DriverAction and SQLType.

有人可以给我一个例子吗?

Can anyone give me an example?

推荐答案

DriverAction

DriverAction 仅与驱动程序的实现相关,如果该驱动程序想要被告知该驱动程序是否已注销(例如释放资源或执行其他清理操作),作为JDBC的最终用户,您将与它无关.

DriverAction

DriverAction is only relevant for driver implementations, if that driver wants to be informed if the driver is deregistered (eg to release resources or to perform other clean up actions), as an end-user of JDBC you have nothing to do with it.

其目的是,如文档中所述:

Its purpose is, as described in the documentation:

Driver希望由DriverManager通知时必须实现的接口.

An interface that must be implemented when a Driver wants to be notified by DriverManager.

DriverAction实现不是不能直接由应用程序使用. JDBC驱动程序可以选择在私有类中创建其DriverAction实现,以避免直接调用它.

A DriverAction implementation is not intended to be used directly by applications. A JDBC Driver may choose to create its DriverAction implementation in a private class to avoid it being called directly.

(重点是我的)

要了解 SQLType 您首先需要查看枚举 JDBCType .这是一个声明与相同的JDBC类型的枚举. java.sql.Types ,但随后作为枚举对象.该枚举实现SQLType.接口SQLType的添加使驱动程序实现可以为JDBC中未定义的特定于驱动程序或数据库的类型添加类似的类型安全枚举.

To understand SQLType you first need to look at the enum JDBCType. This is an enum that declares the same JDBC types as in java.sql.Types, but then as enum objects. This enum implements SQLType. The addition of the interface SQLType allows driver implementations to add similar type safe enums for driver or database specific types that are not defined in JDBC.

例如在您可能会问这是什么?首先,它对类型安全性更好.过去,驱动程序为特定于数据库的类型分配类似于java.sql.Types的整数,这些整数可能与在较新的JDBC版本中添加的类型代码冲突.其次,当您提供不受支持的类型时(例如,代替不受支持的类型-1233" ),它可能会显示不受支持的XYZ类型(供应商:MyXYZDB)" 使用 getName getVendor )方法,最后(也是类型安全的一种形式),它防止用户错误地使用数据库品牌Y中的数据库品牌X的类型代码(或至少:允许驱动程序检测这种不正确的使用).

What does this add you may ask? First of all it is better for type safety. In the past drivers allocated java.sql.Types-like integers for database specific types that might conflict with type codes added in newer JDBC versions. Second it might allow for more readable diagnostics when you provide an unsupported type (eg instead of "Unsupported type -1233" it could display "Unsupported type XYZ (vendor : MyXYZDB)" using the getName and getVendor) methods, and finally (also a form of type safety) it prevents users from incorrectly using the type codes of database brand X in database brand Y (or at least: allow the driver to detect this incorrect use).

这就是说:我认为对于JDBC的大多数基本用法和常规用法,此接口并不会增加太多.

That said: I think that for most basic and regular usages of JDBC this interface does not add much.

这篇关于JDBC 4.2接口DriverAction和SQLType-示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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