added getMaxSubId, and improved resources management (by closing statements)