创建与JDBC 3和4一起使用的java.sql.Connection的包装器 [英] Create a wrapper for java.sql.Connection that works with JDBC 3 and 4

查看:118
本文介绍了创建与JDBC 3和4一起使用的java.sql.Connection的包装器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一些黑客为java.sql.Connection创建一个包装器,它使用JDBC 3和4(Sun添加了几个方法和新类型到JDBC 4的接口)没有到在编译时修补源码的东西?

Is there some hack to create a wrapper for java.sql.Connection which works with JDBC 3 and 4 (Sun added a couple of methods and new types to the interface for JDBC 4) without resorting to something which patches the source at compile time?

我的用例是,我需要生成一个库,它使用Java 5和6,我真的想避免创建两个版本。

My use case is that I need to generate a library which works with Java 5 and 6 and I'd really like to avoid creating two versions of it.

推荐答案

尚未尝试,但可能会有效。

Haven't tried it but it might work.

创建您的类以实现Java 6版本。它将对java.sql中的新类产生问题(NClob,SQLXML,SQLClientInfoException)。假设你不使用这些类(因为你也使用Java 5),创建一个虚拟的实现,并将它放在一个单独的jar。在Java 5部署中,请参阅此jar与 -Xbootclasspath 命令行变量,以便正确加载它们。

Create your class to implement the Java 6 version. It will have problem with the new classes in java.sql (NClob, SQLXML, SQLClientInfoException). Assuming you do not use these classes (as you are working with Java 5 as well), create a dummy implementation of them and put it in a separate jar. In the Java 5 deployment, refer to this jar with the -Xbootclasspath command line variable so they will be loaded correctly.

请注意,你的包装器将需要知道它是否运行在Java 5或6顺序委派正确),所以你可能希望所有的Java 6特性在一个单独的类中处理,在运行时实例化(参见 state design pattern)

Notice that your wrapper will need to know whether it is running on Java 5 or 6 (in order to delegate properly), so you will probably want to have all the Java 6 features handled in a separate class, instantiated in run time (see the state design pattern)

这篇关于创建与JDBC 3和4一起使用的java.sql.Connection的包装器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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