views:

52

answers:

2

Is there a way to detect the ODBC database currently being connected to with Java? For example, I would like to know whether an application is currently connected to Oracle 10g or SQL Server 2005. Thanks in advance.

+5  A: 

If you have java.sql.Connection class, getMetaData method will return database information. From DatabaseMetaData object you can retrieve all kinds of stuff, like driver name or connection url, to determine your kind of server. edit There's also getDatabaseProductName method there.

Nikita Rybak
A: 

Why not extract it from the driver that is in use? IE if your currently using com.mysql.jdbc.Driver, then you know that your using MySQL.

You are passing the driver class name to something, right?

TheLQ
Often you use frameworks to access Connection object (e.g., application servers manage transactions and connection pools for you, you do not create Connection object yourself there). Not sure what's the case here, though.
Nikita Rybak