如果获取数据库表结构?

moneyHao 2006-12-12 02:20:41
想获取数据库中numeric类型或decimal类型的精度信息,如numeric(10,4),decimal(10,4),要获取这个10,4的值,在java里有没有办法做到?
...全文
308 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
moneyHao 2006-12-12
  • 打赏
  • 举报
回复
这里不同的数据库实现取到的值是不是一样的?
moneyHao 2006-12-12
  • 打赏
  • 举报
回复
我用rmd.getColumnDisplaySize(ii)取字char或varchar类型的,用getPrecision取数字类型的.
moneyHao 2006-12-12
  • 打赏
  • 举报
回复
谢谢两位,shine333(enihs) 的方法我试了,对于数字类型是可以的.
wunan320 2006-12-12
  • 打赏
  • 举报
回复
接口DatabaseMetaData是关于数据库的整体综合信息。个人感觉用这个取比较好。
wunan320 2006-12-12
  • 打赏
  • 举报
回复
jdbc有的。假设有个con
DatabaseMetaData dbmd = con.getMetaData();
rs = dbmd.getColumns(con.getCatalog(), schema, tableName, null);
rs.getString(DATA_TYPE) java.sql.Types 的 SQL 类型
rs.getString(COLUMN_SIZE) 列的大小。对于 char 或 date 类型,列的大小是最大字符数,对于 numeric 和 decimal 类型,列的大小就是精度。
rs.getString(DECIMAL_DIGITS) 小数部分的位数
shine333 2006-12-12
  • 打赏
  • 举报
回复
java.sql.ResultSetMetaData:

/**
* Get the designated column's number of decimal digits.
*
* @param column the first column is 1, the second is 2, ...
* @return precision
* @exception SQLException if a database access error occurs
*/
int getPrecision(int column) throws SQLException;

/**
* Gets the designated column's number of digits to right of the decimal point.
*
* @param column the first column is 1, the second is 2, ...
* @return scale
* @exception SQLException if a database access error occurs
*/
int getScale(int column) throws SQLException;



ResultSetMetaData rsmd = rs.getMetaData()

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧