使用oracle jdbc连接时如何获取数据库架构名称? [英] How to get database schema name when using oracle jdbc connection?
问题描述
我正在尝试使用DatabaseMetaData.getTables()方法获取所有数据库表.但是此方法需要数据库模式名称模式.是否可以获取当前数据库连接的架构名称?
I am trying to get all db tables using DatabaseMetaData.getTables() method. But this method requires database schema name pattern. Is it possible to get schema name for current db connection?
推荐答案
当前连接的标准架构是您用于登录的用户的名称.因此,如果您的用户是SCOTT
,则必须使用DatabaseMetaData.getTables()
.
The standard schema for your current connection is the name of the user you use to log in. So if your user is SCOTT
you have to use SCOTT
for DatabaseMetaData.getTables()
.
您可以通过DatabaseMetaData.getUserName()
获取用户名.
You can obtain the username through DatabaseMetaData.getUserName()
.
但是请记住,在JDBC驱动程序中完成的模式/用户名的比较区分大小写,并且用户名通常是大写的.
But remember that the comparison of schema/username done in the JDBC driver is case-sensititve and normally usernames are in uppercase.
我不确定100%是否会在所有情况下均以正确的情况返回DatabaseMetaData.getUserName()
的名称.可以肯定的是,您可能需要在使用该值之前先做一个upperCase().
I am not 100% sure if DatabaseMetaData.getUserName()
will return the name in the correct case in all situations. To be sure, you might want to do an upperCase() before using that value.
这篇关于使用oracle jdbc连接时如何获取数据库架构名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!