Connection pooling
Use a connection pool. Each transaction in your app will get a connection from this pool, execute all the things needed, rollback or commit and close the connection (it will return the conn to the pool).
You could give you Query object a reference to the pool and open will get the connection and close will close it (returning it in fact).
Prepared Statement
Try to reuse your prepared statement for similar queries. That way the DB will reuse the previous query plan and it will be faster. It has a lot of sense if you are executing a lot of queries of the same form.
How?
- Maintain last PS open
- If you close the connection or whatever, close it
- if you query for the same query string than the previous reuse the PS you saved
- if it's not the same query string... close it and create a new one