我正在使用Apache DBCP获取连接池,我每次都使用PoolingDataSource获取连接。当我向数据库中插入一个对象时它工作的很好,但是当我尝试从数据库中选择一个元素时会发生问题:它总是返回一个DelegatingPreparedStatement和DelegatingResultSet,并且如果DelegatingResuletSet的next()方法执行,则会出现一个错误“java.sql .SQLException:无效光标状态:标识的光标未打开标识的光标未打开“出现。我不知道为什么,有没有人知道问题是什么?我正在使用HSQLDB。该代码是:java.sql.SQLException:光标状态无效:标识的光标未打开标识的光标未打开
String strSql = "select * from " + strTableName + " where " + strColumnName
+ " = ? ";
PreparedStatement aPreparedStatement = con.prepareStatement(strSql);
ResultSet aResultSet = null;
/*
* Execute the query
*/
try
{
aPreparedStatement.setString(1, strValue);
aResultSet = aPreparedStatement.executeQuery();
}
catch (SQLException theException)
{
aPreparedStatement.close();
throw theException;
}
aPreparedStatement.close();
while (theResultSet.next())
{
// do something else
}
感谢您的帮助, 艾克