如何从jdbc连接获取驱动程序类名(不是驱动程序名) [英] How to get driver class name (not driver name) from jdbc connection
问题描述
我有以下格式的context.xml文件
I have a context.xml file in the below format
<Context shallowOutput="true" path="/">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="jdbc/myDataSource"
auth="Container"
type="javax.sql.DataSource"
factory="org.apache.commons.dbcp.BasicDataSourceFactory"
driverClassName="oracle.jdbc.driver.OracleDriver"
username="OMITTED"
password="OMITTED"
url="OMITTED"
maxActive="20"
maxIdle="10"
maxWait="-1"/>
从这个contex.xml我需要获取我的驱动程序CLASS名称。
From this contex.xml I need to get my Driver CLASS name.
每次我尝试
DataSource ds =(DataSource)context.lookup(java:/ jdbc / myDataSource)
并尝试从中获取驱动程序类名称连接使用
and try to like get the the Driver Class name from the connection using
ds.getConnection()。getMetatData()。getDriverName()
它只返回
Oracle JDBC驱动程序 而不是类名 oracle.jdbc.driver.OracleDriver
如何从上下文中获取类名。
How can I get the class name from the context.
推荐答案
我认为你能想到的最好的是:
I think the best you can hope for is:
DriverManager.getDriver(ds.getConnection().getMetaData().getURL()).getClass();
元数据应该返回此连接的URL,并且URL前缀应该使用DriverManager注册(唯一的)。
The metadata should return the URL for this connection and the URL prefix should be registered with the DriverManager (uniquely).
这篇关于如何从jdbc连接获取驱动程序类名(不是驱动程序名)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!