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"/>
From this contex.xml I need to get my Driver CLASS name.
Everytime I try like
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()
It is returning just Oracle JDBC Driver instead of the class name oracle.jdbc.driver.OracleDriver
How can I get the class name from the context.
One way to check the JDBC driver version is to open the ojdbc jar file and go inside the META-INF folder, and then open the "MANIFEST. MF" file. The version can be seen next to "Specification-Version".
Use the Class. forName() method to load the driver. The forName() method dynamically loads a Java class at runtime. When an application calls the forName() method, the Java Virtual Machine (JVM) attempts to find the compiled form (the bytecode) that implements the requested class.
I think the best you can hope for is:
DriverManager.getDriver(ds.getConnection().getMetaData().getURL()).getClass();
The metadata should return the URL for this connection and the URL prefix should be registered with the DriverManager (uniquely).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With