how to find out which type of the driver is used in our application?

Hi all,can anyone tell me how to find out which type of the driver is used in our application?Thanks in advance,Phoeniox
[148 byte] By [Phoenioxa] at [2007-11-27 4:40:13]
# 1
Do you mean this application or the one over there? :)If you mean progromatically have you tried DriverManager.getDrivers()?
ChristopherAngela at 2007-7-12 9:51:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
Hi,Thanks for ur reply.> Do you mean this application or the one over there? :)I mean in any web application. if anyone is connecting to the database how tofind out which type of driver they are using?Phoeniox
Phoenioxa at 2007-7-12 9:51:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

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.

ChristopherAngela at 2007-7-12 9:51:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
Thanks...> Look in the directories for any databases drivers. which directory... i am using MySql... and also i am not using driver manager... i'm using datasource.... Thanks..Phoeniox
Phoenioxa at 2007-7-12 9:51:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

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.

ChristopherAngela at 2007-7-12 9:51:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

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();

}

>

java_2006a at 2007-7-12 9:51:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7

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.

dcmintera at 2007-7-12 9:51:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 8

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>

prakhyatha at 2007-7-12 9:51:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 9
Hi all,Thanks all of you... i got the required result...How to diffrentiate drivers drivers as 1 ,2 3 and 4... by name or any other factor.... What is the fastest type of JDBC driver?when to use which driver..?Phoeniox
Phoenioxa at 2007-7-12 9:51:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 10

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!?)

dcmintera at 2007-7-12 9:51:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 11

> 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...

Phoenioxa at 2007-7-12 9:51:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 12
In general the application itself never does this. Hence the lack of an easy API to help you do it.And when you personally need to know, you look it up in the documentation.
dcmintera at 2007-7-12 9:51:08 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...