[英]How can I determine whether a JDBC driver is Type 4?
We have an application that runs on Java 1.6 and has the ability to talk to RDBMS systems via custom plugins. 我们有一个在Java 1.6上运行的应用程序,它能够通过自定义插件与RDBMS系统通信。 We don't care what type of database a customer has, but we did decide to require a Type 4 driver, for a variety of reasons.
我们不关心客户的数据库类型,但出于各种原因,我们确实决定要求使用Type 4驱动程序。
I want to programmatically decide whether a driver is Type 4 so that I can reject it right away rather than spend time debugging problems later only to find out that the driver is not Type 4. Since I don't know what the vendor is, I can't just look at the version number. 我想以编程方式确定驱动程序是否为Type 4,以便我可以立即拒绝它,而不是花时间调试问题以后才发现驱动程序不是Type 4.因为我不知道供应商是什么,我不能只看版本号。 I've looked at Driver.jdbcCompliant() but this is not a necessary condition for the driver being Type 4. I've also looked at creating a Connection and then doing reflection on it to see if it implements certain methods like isValid(), but again I realized this does not necessarily guarantee the driver is Type 4. Any suggestions?
我看过Driver.jdbcCompliant(),但这不是驱动程序是Type 4的必要条件。我还看了创建一个Connection然后对它进行反射,看看它是否实现了某些方法,如isValid() ,但我再次意识到这并不一定能保证驱动程序是Type 4.有什么建议吗?
Edit: Seems like I was talking about something different anyway! 编辑:似乎我正在谈论不同的东西!
Get the DatabaseMetaData
via Connection.getMetaData()
and check that getJDBCMajorVersion() >= 4. You may want to catch NoSuchMethodException
when calling that method, since only a JDBC 3.0+ driver will have it. 通过
Connection.getMetaData()
获取DatabaseMetaData
并检查getJDBCMajorVersion() > = 4.您可能希望在调用该方法时捕获NoSuchMethodException
,因为只有JDBC 3.0+驱动程序才会拥有它。
Edit: Hmm, this seems like it should be right but... Oracle doesn't seem to implement it correctly, since I get 11.2 for the JDBC version. 编辑:嗯,这似乎应该是正确的但是...... Oracle似乎没有正确实现它,因为我获得了11.2的JDBC版本。 That's the same thing I get for the driver version.
这与驱动程序版本相同。 Thanks Oracle!
谢谢甲骨文!
If you can't count on the methods specifically designed for this, it seems to me that your only option is to call methods like createClob()
on Connection
and catch NoSuchMethodException
. 如果您不能指望专门为此设计的方法,在我看来,您唯一的选择是在
Connection
上调用createClob()
等方法并捕获NoSuchMethodException
。 That or add special handling for specific vendors. 那或为特定供应商添加特殊处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.