Created
September 7, 2017 06:19
-
-
Save vigack/c5fce1ce2704f50514e84820aa301e4d to your computer and use it in GitHub Desktop.
奇妙BUG记录
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Table getTable(String scheme, String tableName){ | |
Connection connection = null; | |
Table table = new Table(); | |
table.setTableName(tableName); | |
try { | |
List<Column> columns = new ArrayList<>(); | |
connection = getConnection(scheme); | |
ResultSet resultSet = | |
connection.getMetaData().getColumns(null, null,tableName,null); | |
while(resultSet.next()){ | |
Column column = new Column(); | |
String name = resultSet.getString("COLUMN_NAME"); | |
int type = resultSet.getInt("DATA_TYPE"); | |
String typeName = resultSet.getString("TYPE_NAME"); | |
int length = resultSet.getInt("COLUMN_SIZE"); | |
boolean nullable = resultSet.getInt("NULLABLE")==1; | |
String remark = resultSet.getString("REMARKS"); | |
Object defaultValue = resultSet.getObject("COLUMN_DEF"); | |
column.setName(name); | |
column.setType(type); | |
column.setTypeName(typeName); | |
column.setNullable(nullable); | |
column.setLength(length); | |
column.setRemark(remark); | |
column.setDefaultValue(defaultValue); | |
columns.add(column); | |
} | |
table.setColumns(columns); | |
} catch (SQLException e) { | |
e.printStackTrace(); | |
} finally { | |
close(connection); | |
} | |
return table; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
用jdbc的getMetaData的方式获取列,会获取到重复的列,有时候又获取不到某些字段,很怪异的问题。