我是EasyMock / PowerMock的初学者所以如果有人可以帮助我解决以下问题。 我有以下DAOImpl类,其中我连接到数据库并执行搜索操作。
public List<ShoppingList> getShoppingList(Department department) throws ShoppingListDAOException {
SHOPPING_LIST_QRY1= "{call ec_list_package.get_shopping_lists_id_order(?,?,?,?)}";
connection =null;
ResultSet resultSet =null;
CallableStatement callableStatment = null;
List <ShoppingList> shoppingList = new ArrayList<ShoppingList>();
DataSource ds = null;
try {
if("true".equals(junit)){
connection = getDataSource(true);
}else {
ds = getDataSource();
connection = ds.getConnection();
}
callableStatment = connection.prepareCall(SHOPPING_LIST_QRY1);
callableStatment.setString(1, department.getDistributorNumber());
callableStatment.setString(2, department.getCustomerNumber());
callableStatment.setString(3, department.getDepartmentNumber());
callableStatment.registerOutParameter(4, OracleTypes.CURSOR);
callableStatment.execute();
resultSet= (ResultSet) callableStatment.getObject(4);
while(resultSet.next()) {
.......some code here.....
}
} catch (SQLException e) {
e.printStackTrace();
throw new ShoppingListDAOException(e);
} catch (Exception e) {
e.printStackTrace();
throw new ShoppingListDAOException(e);
}finally{
try {
if(resultSet!=null)
resultSet.close();
if(callableStatment!=null)
callableStatment.close();
if(connection!=null)
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return shoppingList;
}