Posts

Showing posts from May, 2012

Optimized Database access

Optimized Database Interaction: While writing applications for interacting with database using JDBC or using ORM tools like hibernate, we face the problem of optimizing the memory and resource usage. Some tips that would be handy in this: 1. Always close the statements and other resources object after use. 2. Select the specific required fields instead of getting all fields.    eg.      Use           Select OrderId,ItemId from  orderDetails      instead of          select * from orderDetails 3. Use Connection pools 4. Prefer stored procedures instead of direct SQL 5. Turn autocommit off if  not using stored procedures but dont let transactions wait for too long. 6. Tune the SQL to return the minimised data return. 7. User joins instead of sub-queries if possible. 8. Cache data to avoid multiple DB calls for the same data.