Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine database type for a given JDBC connection?

Tags:

java

oracle

jdbc

People also ask

How do I know which database is used in Java?

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.


I suspect you would want to use the DatabaseMetaData class. Most likely DatabaseMetaData.getDatabaseProductName would be sufficient, though you may also want to use the getDatabaseProductVersion method if you have code that depends on the particular version of the particular database you're working with.


You can use org.apache.ddlutils, class Platformutils:

databaseName = new PlatformUtils().determineDatabaseType(dataSource)