我关闭了结果集,但直到显示警告“此行发现多个注释: - 资源泄漏:'resultSet'未在此处关闭 地点 - 资源泄漏:'resultSet'未在此处关闭 位置“
<%
Connection connection = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/sm_db", "root", "root");
Statement statement = connection.createStatement() ;
DatabaseMetaData metadata = connection.getMetaData();
ResultSet resultSet;
resultSet = metadata.getTables(null, null, "SmartMiner", null);
while(resultSet.next())
{
//table exists
try{
resultSet=statement.executeQuery("SELECT*FROM SmartMiner") ;
}finally{
resultSet.close();
}
%>
<div style="overflow-x:auto;">
<table BORDER="1" style="margin-left:112px; border: 2px solid lightblue;">
<%
ResultSetMetaData rsmd = resultSet.getMetaData();
int numOfCols = rsmd.getColumnCount();%>
<tr>
<%for(int i = 1; i <= numOfCols; i++){%>
<th> <%= rsmd.getColumnName(i)%> </th>
<%}%>
</tr>
<%while(resultSet.next()){%>
<tr>
<%for(int i = 1; i <= numOfCols; i++){%>
<td> <%= resultSet.getString(i)%> </td>
<%}%>
</tr>
<%}
}
resultSet.close();
statement.close();%>
</table>