基于Java获取Mysql表结构的步骤
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了基于Java获取Mysql表结构的步骤,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3241字,纯文字阅读大概需要5分钟。
内容图文
![基于Java获取Mysql表结构的步骤](/upload/InfoBanner/zyjiaocheng/558/b5eafb82add84e39a5dac8d3a773bdcd.jpg)
基于Java获取Mysql表结构的方法 Class.forName("com.mysql.jdbc.Driver").newInstance();Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/MALL?user=rootpassword=123456");DatabaseMetaData meta = (DatabaseMetaData) conn.ge
基于Java获取Mysql表结构的方法Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection conn = DriverManager .getConnection("jdbc:mysql://localhost:3306/MALL?user=root&password=123456"); DatabaseMetaData meta = (DatabaseMetaData) conn.getMetaData(); ResultSet rs = meta.getColumns(null, "%", "T_Mall_ReturnOrderInfo", "%"); while (rs.next()) { // table catalog (may be null) String tableCat = rs.getString("TABLE_CAT"); // table schema (may be null) String tableSchemaName = rs.getString("TABLE_SCHEM"); // table name String tableName_ = rs.getString("TABLE_NAME"); // column name String columnName = rs.getString("COLUMN_NAME"); // SQL type from java.sql.Types int dataType = rs.getInt("DATA_TYPE"); // Data source dependent type name, for a UDT the type name is // fully qualified String dataTypeName = rs.getString("TYPE_NAME"); System.out.println(columnName + " " + dataTypeName); // table schema (may be null) int columnSize = rs.getInt("COLUMN_SIZE"); // the number of fractional digits. Null is returned for data // types where DECIMAL_DIGITS is not applicable. int decimalDigits = rs.getInt("DECIMAL_DIGITS"); // Radix (typically either 10 or 2) int numPrecRadix = rs.getInt("NUM_PREC_RADIX"); // is NULL allowed. int nullAble = rs.getInt("NULLABLE"); // comment describing column (may be null) String remarks = rs.getString("REMARKS"); // default value for the column, which should be interpreted as // a string when the value is enclosed in single quotes (may be // null) String columnDef = rs.getString("COLUMN_DEF"); // int sqlDataType = rs.getInt("SQL_DATA_TYPE"); // int sqlDatetimeSub = rs.getInt("SQL_DATETIME_SUB"); // for char types the maximum number of bytes in the column int charOctetLength = rs.getInt("CHAR_OCTET_LENGTH"); // index of column in table (starting at 1) int ordinalPosition = rs.getInt("ORDINAL_POSITION"); // ISO rules are used to determine the nullability for a column. // YES --- if the parameter can include NULLs; // NO --- if the parameter cannot include NULLs // empty string --- if the nullability for the parameter is // unknown String isNullAble = rs.getString("IS_NULLABLE"); // Indicates whether this column is auto incremented // YES --- if the column is auto incremented // NO --- if the column is not auto incremented // empty string --- if it cannot be determined whether the // column is auto incremented parameter is unknown String isAutoincrement = rs.getString("IS_AUTOINCREMENT"); System.out.println(tableCat + "-" + tableSchemaName + "-" + tableName_ + "-" + columnName + "-" + dataType + "-" + dataTypeName + "-" + columnSize + "-" + decimalDigits + "-" + numPrecRadix + "-" + nullAble + "-" + remarks + "-" + columnDef + "-" + sqlDataType + "-" + sqlDatetimeSub + charOctetLength + "-" + ordinalPosition + "-" + isNullAble + "-" + isAutoincrement + "-"); } conn.close();
?
内容总结
以上是互联网集市为您收集整理的基于Java获取Mysql表结构的步骤全部内容,希望文章能够帮你解决基于Java获取Mysql表结构的步骤所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。