简体   繁体   English

如何从Connection对象中确定DBMS

[英]How to determine the DBMS from Connection object

I have a usecase of supporting multiple RDBMS. 我有一个支持多个RDBMS的用例。 User should define the data source as a prerequisite and at the code level i have to determine which RDBMS the user going to connect with and provide specific RDBMS attributes. 用户应该将数据源定义为先决条件,并且在代码级别,我必须确定用户要连接哪个RDBMS并提供特定的RDBMS属性。

Eg:, 例如:,

com.mysql.jdbc.Driver           jdbc:mysql://hostname/ databaseName
oracle.jdbc.driver.OracleDriver jdbc:oracle:thin:@hostname:port Number:databaseName

As shown above we can retrieve connection url or may be driver name and identify the RDBMS. 如上所示,我们可以检索连接URL或可能是驱动程序名称并标识RDBMS。 But i want to clarify what is the best way to identify which RDBMS user is using. 但我想澄清一下识别哪个RDBMS用户正在使用的最佳方法。 Any help would be greatly appreciated. 任何帮助将不胜感激。

This is really simple. 这很简单。 See DatabaseMetaData 请参见DatabaseMetaData

DatabaseMetaData databaseMetaData = connection.getMetaData();
String databaseName = databaseMetaData.getDatabaseProductName();
String userName = databaseMetaData.getUserName();

UPDATE To answer @dnWick comment. 更新回答@dnWick评论。

Yes, This DatabaseMetaData support for the wide range of RDBMS . 是的,这个DatabaseMetaData支持广泛的RDBMS Through the DatabaseMetaData interface we can obtain metadata about the database that we have connected. 通过DatabaseMetaData接口,我们可以获取有关我们已连接的数据库的元数据。 For instance, we can see what tables are defined in the database, and what columns each table has, Even we can check supported features for the database we have connected. 例如,我们可以看到数据库中定义了哪些表,以及每个表有哪些列,甚至我们可以检查我们连接的数据库的支持功能。

Example We can see if a database has support for multiple transactions, supports for UNION or not, etc., 示例我们可以看到数据库是否支持多个事务,是否支持UNION等,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何确定传入连接来自本地计算机 - How to determine an incoming connection is from local machine 如何从数据源连接确定有关WebLogic数据源的信息? - How to determine info about WebLogic datasource from datasource connection? 如何验证从连接池返回的连接对象? - How to verify the connection object returned from connection pool? 如何在春季从Java存储库中触发dbms_scheduler作业? - How to trigger a dbms_scheduler job from Java repo in Spring? 如何将数据从Oracle中的(PL /)SQL复制到另一个DBMS? - How to copy data from (PL/)SQL in Oracle to another DBMS? 如何从Java调用oracle dbms_scheduler.run_job? - How to call oracle dbms_scheduler.run_job from java? 如何在Java Web应用程序中跟踪连接池 - DBMS_APPLICATION_INFO - How to trace the connection pool in a Java Web application - DBMS_APPLICATION_INFO HttpServletResponse:如何确定基础连接是否仍处于打开状态? - HttpServletResponse : How to determine if the underlying connection is still open? 从未初始化的对象确定所需的对象类型 - Determine required object type from uninitialized object 如何确定给定JDBC连接的数据库类型? - How to determine database type for a given JDBC connection?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM