我收到以下错误
[Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt
我的代码
private static final String DRIVER = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
private static final String URL = "jdbc:odbc:sql2008";
private String[] entity = {"TABLE","VIEW"};
private ResultSet tables,columns,resultSet;
public void getData() throws SQLException, ClassNotFoundException{
Class.forName(DRIVER);
Connection connection=DriverManager.getConnection(URL,USERNAME,PASSWORD);
DatabaseMetaData data = connection.getMetaData();
resultSet = data.getCatalogs();
while (resultSet.next()) {
String dbName = resultSet.getString("TABLE_CAT");
if(dbName.toString().equals("db")){
tables=data.getTables(dbName, "%", "%", entity);
while (tables.next()) {
System.out.println(tables.getString("TABLE_NAME"));
}
}
}
}
URL 是 DSN 连接(使用 dsn 名称的连接),我在尝试获取再次是 ResultSet 的表时遇到此错误,但它在直接(使用地址)的无 DSN 连接中工作正常