establishing a database connection and executing sql statement