results = statement.executeQuery("SELECT * FROM " + database + ".dbo." + tablename);
ResultSetMetaData metaData = results.getMetaData();
if (metaData != null) {
System.out.println(database + ".dbo." + tablename+"ColumnCount()"+metaData.getColumnCount());
for (int i = 1; i < metaData.getColumnCount(); i++) {
columnMap.put(metaData.getColumnName(i), metaData.getColumnTypeName(i));
}
}
答案 0 :(得分:0)
您收到该错误是因为ResultSetMetaData是基于1的列表。
将您的代码更改为:
results = statement.executeQuery("SELECT * FROM " + database + ".dbo." + tablename);
ResultSetMetaData metaData = results.getMetaData();
if (metaData != null) {
System.out.println(database + ".dbo." + tablename+"ColumnCount()"+metaData.getColumnCount());
for (int i = 1; i <= metaData.getColumnCount(); i++) {
columnMap.put(metaData.getColumnName(i), metaData.getColumnTypeName(i));
}
}
以下是使用ResultSetMetaData的示例: