最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

基于Java获取Mysql表结构的步骤

来源:动视网 责编:小采 时间:2020-11-09 13:34:38
文档

基于Java获取Mysql表结构的步骤

基于Java获取Mysql表结构的步骤:基于Java获取Mysql表结构的方法 Class.forName(com.mysql.jdbc.Driver).newInstance();Connection conn = DriverManager.getConnection(jdbc:mysql://localhost:3306/MALLuser=rootpassword=1234
推荐度:
导读基于Java获取Mysql表结构的步骤:基于Java获取Mysql表结构的方法 Class.forName(com.mysql.jdbc.Driver).newInstance();Connection conn = DriverManager.getConnection(jdbc:mysql://localhost:3306/MALLuser=rootpassword=1234

基于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表结构的步骤:基于Java获取Mysql表结构的方法 Class.forName(com.mysql.jdbc.Driver).newInstance();Connection conn = DriverManager.getConnection(jdbc:mysql://localhost:3306/MALLuser=rootpassword=1234
推荐度:
标签: 步骤 方法 获取
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top