use cursor and must close it in the end