获取MySQL元信息包括数据库,表,字段,类型等(代码怎么格式显示不正常) package com.wp.tool.sql;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.ResultSetMetaDa
package com.wp.tool.sql; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.sql.DataSource; public class MySQLTableMeta { private DataSource dataSource; public static final String SQL_DATABASES = "SELECT t.`SCHEMA_NAME` FROM `information_schema`.`SCHEMATA` t"; public static final String SQL_TABLES = "SELECT " + " b.`TABLE_NAME`, " + " b.`TABLE_TYPE` " + "FROM " + " `information_schema`.`SCHEMATA` a " + " LEFT JOIN `information_schema`.`TABLES` b " + " ON a.`SCHEMA_NAME` = b.`TABLE_SCHEMA` " + "WHERE a.`SCHEMA_NAME` = ? "; public static final String SQL_COLUMNS = "SELECT " + " c.`TABLE_NAME`, " + " c.`COLUMN_NAME`, " + " c.`COLUMN_TYPE`, " + " c.`DATA_TYPE` " + "FROM " + " `information_schema`.`SCHEMATA` a " + " LEFT JOIN `information_schema`.`TABLES` b " + " ON a.`SCHEMA_NAME` = b.`TABLE_SCHEMA` " + " LEFT JOIN `information_schema`.`COLUMNS` c " + " ON b.`TABLE_NAME` = c.`TABLE_NAME` " + "WHERE a.`SCHEMA_NAME` = ? " + " AND b.`TABLE_NAME` = ? "; public static final String COLUMN_SCHEMA_NAME = "SCHEMA_NAME"; public static final String COLUMN_TABLE_NAME = "TABLE_NAME"; public static final String COLUMN_TABLE_TYPE = "TABLE_TYPE"; public static final String COLUMN_COLUMN_NAME = "COLUMN_NAME"; public static final String COLUMN_COLUMN_TYPE = "COLUMN_TYPE"; public static final String COLUMN_DATA_TYPE = "DATA_TYPE"; /** ** getMeta info: * SQL_DATABASES:SCHEMA_NAME * SQL_TABLES:TABLE_NAME,TABLE_TYPE PARAMS:SCHEMA_NAME * SQL_COLUMNS:TABLE_NAME,COLUMN_NAME,COLUMN_TYPE,DATA_TYPE PAEAMS:SCHEMA_NAME,TABLE_NAME ** * @param sql * @param params * @return */ public List