JDBC执行SQL语句后的问题。
我按照下面的操作
1.打开数据库。
2.执行SQL语句,获得ResultSet。
3.关闭数据库。
那么,这个ResultSet还能使用吗?还能进行遍历吗?
简单代码如下:
if (this.connection == null)
{
this.connection = DriverManager.getConnection(this.connectionString, this.connectionName, this.connectionPassword);
}
if (this.preparedStatement != null)
{
this.preparedStatement.close();
this.preparedStatement = null;
}
this.preparedStatement = connection.prepareStatement(sql);
ResultSet resultSet = this.preparedStatement.executeQuery();
if (this.connection != null)
{
this.connection.close();
this.connection = null;
}
resultSet.next();