获取数据库信息(二)

本文详细介绍了如何获取数据库信息,包括数据类型详情、表信息、表的主键列、允许的表类型、列信息以及索引信息,是数据库管理和开发的重要参考资料。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 m) local_type_name: 被本地化了的数据类型名

n) minimum_scale: 支持的最小精度

o) maximum_scale: 支持的最大精度

p) sql_data_type: 未用

q) sql_datetime_sub: 未用

r) num_prec_radix: 此数据类型的基数, 为2或10

 

//例子
ResultSet rs=dbmd.getTypeInfo();

//获取JDBC驱动程序的名字
String getDriverName() throws SQLException

//获取数据库的产品名
String getDatabaseProductName() throws SQLException
 
//攻取列名字允许的最大字符数
int getMaxColumnNameLength() throws SQLException

//得到select子句所能返回的最多列数
int getMaxColumnsInSelect() throws SQLException

//得到在一表中允许的最多列数
int getMaxColumnsInTable() throws SQLException

//得到通过这个驱动程序实例最多可以有多少用户连接到这个数据库
int getMaxConnections() throws SQLException

//得到SQL语句最大允许的长度
int getMaxStatementLength() throws SQLException

//得到表名允许的最大的长度
int getMaxTableNameLength() throws SQLException

//获取一个select语句最多访问的表的数量
int getMaxTablesInSelect() throws SQLException

//返回一个数据库的所有数学函数的列表,是一个用逗号分隔的字符串
String getNumericFunctions() throws SQLException

//获取数据库中的模式名
ResultSet getSchemas() throws SQLException

//获取数据库中SQL语句的关键词
String getSQLKeywords() throws SQLException

//获取数据库中字符串函数列表
String getStringFunctions() throws SQLException

//获取数据库的系统函数
String getSystemFunctions() throws SQLException

//获取一个数据库中所有时间和日期的库函数名列表
String getTimeDateFunctions() throws SQLException

//获得此数据库的URL
String getURL() throws SQLException

//获得用户名
String getUserName() throws SQLException

//获取数据库的“只读”属性
boolean isReadOnly() throws SQLException


 

三、获取数据库中表的信息

1、获取可用表

ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String types[]) throws SQLException
//catalog: 一个目录名
//schemaPattern: 模式名匹配模式
//tableNamePattern: 代表了一个表名的模式
//types[]: 代表了一个表类型的字符串,如果为null则代表所有类型的表都被返回
//例:
String[] s={"TABLE""VIEW"};
ResultSet rs
=dbmd.getTables(null"HR""%", s);



2、获取表的主键列

ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException
//catalog: 代表目录名的字符串, 通常为null
//schema: 模式名在oracle中为表所在的空间
//table: 表名

//例:
ResultSet rs=dbmd.getPrimaryKeys(null"HR""employees");

3、获取数据库中允许的表的类型

ResultSet getTableTypes() throws SQLException
//例:
ResultSet rs=dbmd.getTableTypes();

四、获取表中各列的信息

1、获取列访问权限信息

ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) throws SQLException
//catalog: 代表一个目录名的字符串
//schema: 代表模式名的字符串
//table: 代表一个表名的字符串
//columnNamePattern: 代表一个供匹配的列名模式

2、获取列信息

ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException
//catalog: 代表一个目录名的字符串
//schemaPattern: 代表模式名匹配模式的字符串
//tableNamePattern: 代表一个表名匹配模式的字符串
//columnNamePattern:代表一个供匹配的列名模式

五、获取索引的信息

 

ResultSet getIndexInfo(String catalog, String schema, String table, Boolean unique, Boolean approximate) throws SQLException
//catalog: 代表一个目录名的字符串
//schema: 代表模式名的字符串
//table: 代表了表名的字符串
//unique: 如果为true,那么就返回所有单独的键值的索引, 如果是false, 就返回所有的键值的索引而不管这个列的值是不是唯一的
//Approximate: 如是真,则允许返回估计值, 如是否, 则必须要返回精确值 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值