| | |
| | | |
| | | import org.springframework.jdbc.core.JdbcTemplate; |
| | | |
| | | import java.sql.Connection; |
| | | import java.sql.DatabaseMetaData; |
| | | import java.sql.ResultSet; |
| | | import java.sql.SQLException; |
| | | import java.sql.*; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | public class DBUtil { |
| | |
| | | try { |
| | | DatabaseMetaData dbm = conn.getMetaData(); |
| | | String currentCatalog = conn.getCatalog(); |
| | | String[] types = { "TABLE" }; |
| | | String[] types = {"TABLE"}; |
| | | ResultSet tabs = dbm.getTables(currentCatalog, null, tableName, types); |
| | | if (tabs.next()) { |
| | | return true; |
| | |
| | | try { |
| | | DatabaseMetaData dbm = conn.getMetaData(); |
| | | String currentCatalog = conn.getCatalog(); |
| | | |
| | | Map<String, String> mapDict = new HashMap<>(); |
| | | String sql = "SELECT * FROM sys_dict_type WHERE is_delete=0"; |
| | | PreparedStatement preparedStatement = conn.prepareStatement(sql); |
| | | ResultSet resultSet = preparedStatement.executeQuery(); |
| | | while (resultSet.next()) { |
| | | String dictType = resultSet.getString("DICT_TYPE"); |
| | | mapDict.put(dictType, dictType); |
| | | } |
| | | |
| | | ResultSet rs = dbm.getColumns(currentCatalog, null, tableName, null); |
| | | |
| | | DataTable dt = new DataTable(rs); |
| | | |
| | | rs = dbm.getPrimaryKeys(currentCatalog, null, tableName); |
| | | DataTable keyDt = new DataTable(rs); |
| | | Map map = keyDt.toMap("Column_Name", "PK_Name"); |
| | | dt.insertColumn("isKey"); |
| | | dt.insertColumn("dictType"); |
| | | for (int i = 0; i < dt.getRowCount(); i++) { |
| | | DataRow dr = dt.getDataRow(i); |
| | | if (map.containsKey(dr.getString("Column_Name"))) { |
| | | String columnName = dr.getString("Column_Name"); |
| | | if (map.containsKey(columnName)) { |
| | | dr.set("isKey", "Y"); |
| | | } else { |
| | | dr.set("isKey", "N"); |
| | | } |
| | | if (mapDict.get(columnName) != null) { |
| | | dr.set("dictType", columnName); |
| | | } else { |
| | | dr.set("dictType", ""); |
| | | } |
| | | } |
| | | return dt; |
| | | } catch (Exception e) { |