ah I see.
My first thought was you might be able to get this information through JNDI of which I know little but my suspicion is there will security issues with this.
Even if this were possible through JNDI a web app can still make a connection to a database without using JNDI which you would not then pickup.
Anyway based on this my suggestion is not very elegant: Look in the directories for any databases drivers.
I'm not sure what you're asking?
If you want to do this dynamically during execution then see my response above.
If you want to do this as a one off because you don't know then this should be specified when you defined the datasource.
I use tomcat I don't know if all webapps are the same so I will tell you how to do it in tomcat:
Normally there is a file \web\META-INF\context.xml and the drivers are defined in here.
If find this confusing as you must know which database you are using. Therefore you must know which drivers you are using.
This example lists all loaded JDBC drivers and gets information about each one.
List drivers = Collections.list(DriverManager.getDrivers());
for (int i=0; i<drivers.size(); i++) {
Driver driver = (Driver)drivers.get(i);
// Get name of driver
String name = driver.getClass().getName();
// Get version info
int majorVersion = driver.getMajorVersion();
int minorVersion = driver.getMinorVersion();
boolean isJdbcCompliant = driver.jdbcCompliant();
}
>
Acquire a connection, call getMetaData() and call the getDriverName method on the DatabaseMetaData object. This has the advantage that it ought to work even for wrapped connection objects returned from a remote DataSource.
It does, however, require that the driver support the appropriate metadata methods.
Hi,
Check out this...
Class.forName("com.mysql.jdbc.Driver"); //if u r using MySql
List drivers = Collections.list(DriverManager.getDrivers());
for(int i=0;i<drivers.size();i++)
{
Driver driver = (Driver)drivers.get(i);
String driverName = driver.getClass().getName();
System.out.println("Driver "+i+":::"+driverName);
}
you need to load the driver and display in the same program.
Then only you'l get the required result.
prakhyath>
I'm wondering why you need to know?
Normally your code just takes the connection it's given and uses it as-is - why the connection mechanism underlying it is no concern of your application, and if your application DOES need to know then this may imply a problem with your application architecture.
As far as I know the JDBC driver is not obliged to report the driver type, so I think you're out of luck anyway.
(PS What's with prakhyath plagiarising the preceding post - does he think we won't notice or something!?)
> Normally your code just takes the connection it's given and uses it as-is - why the connection mechanism underlying it is no concern of your application, and if your application DOES need to know then this may imply a problem with your application architecture.
i am not talking abt my application..
I general in application.. how to find out the type driver used...(1,2,3 0r 4)...
which is better.. and when...