BeginnerAmongBeginners
BeginnerAmongBeginners

Reputation: 279

Detect Database Currently in Use with Java

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.

Upvotes: 1

Views: 1189

Answers (2)

Nikita Rybak
Nikita Rybak

Reputation: 68006

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.

Upvotes: 6

TheLQ
TheLQ

Reputation: 15008

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?

Upvotes: 1

Related Questions