检测当前使用 Java 的数据库
有没有办法检测当前使用Java连接的ODBC数据库? 例如,我想知道某个应用程序当前连接的是 Oracle 10g 还是 SQL Server 2005。 提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有
java.sql.Connection
类,getMetaData
方法将返回数据库信息。从DatabaseMetaData
对象中,您可以检索各种内容,例如驱动程序名称或连接 URL,以确定您的服务器类型。 edit 那里还有getDatabaseProductName
方法。If you have
java.sql.Connection
class,getMetaData
method will return database information. FromDatabaseMetaData
object you can retrieve all kinds of stuff, like driver name or connection url, to determine your kind of server. edit There's alsogetDatabaseProductName
method there.为什么不从正在使用的驱动程序中提取它? IE如果你当前使用com.mysql.jdbc.Driver,那么你就知道你使用的是MySQL。
您正在将驱动程序类名称传递给某些东西,对吗?
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?