用DatabaseMetaData.getColumns获取了Oracle数据库的某个表Column的属性,
用next输出时所有Column的属性已经打印完了,
但是他还会至少多循环两遍,所有的Column的属性从新打一遍
比如一个表两个字段,执行一遍,按正常来说有两个打印,
但是有四个,重复两遍
特别奇怪的事有些表没有这种情况
请问这是什么情况?
@Override
public void getColumnsInfo() {
// 创建一个数据库连接
Connection connection = null;
// 创建一个结果集对象
ResultSet rs = null;
OperateOracle oracle = new OperateOracleImpl();
try {
connection = oracle.getOracleConnection();
DatabaseMetaData metaData = connection.getMetaData();
rs = metaData.getColumns(null,null,tableName,null);
while (rs.next()){
String isPk = "false";
String tableName_ = rs.getString("TABLE_NAME");
String columnName = rs.getString("COLUMN_NAME");
int dataType = rs.getInt("DATA_TYPE");
String isAutoincrement = rs.getString("IS_AUTOINCREMENT") == "NO" ? "false" : "true";
int columnSize = rs.getInt("COLUMN_SIZE");
String isNullable = rs.getString("IS_NULLABLE") == "NO" ? "false" : "true";
String remarks = rs.getString("REMARKS");
int index = rs.getInt("ORDINAL_POSITION");
// if(map.containsKey(columnName)){
// isPk = "true";
// }
System.out.println("\t<attribute attrName=\"" + tableName_ + "_" + columnName + "\" isFakeColumn=\"false\" " +
"dataType=\"" + dataType + "\" " + "isPrimaryKey=\""+ isPk + "\" " + "isAutoIncrement=\"" + isAutoincrement + "\" " +
"maxlength=\"" + columnSize + "\" " + "columnName=\"" + columnName + "\" " +
"isNullable=\"" + isNullable + "\" " + "index=\"" + index + "\" " +
"tableName=\"" + tableName_ + "\"/>");
}
System.out.println("</attributes>\n" +
"\n" +
"</dataSetConf>");
//map.clear();
} catch (SQLException e) {
e.printStackTrace();
} finally {
oracle.ReleaseResource(connection,rs);
}
}