Tuesday 29 April 2008

The Good to Great performance in a JDBC application

Few points to consider:

* Use a connection pools wherever possible.

* Use prepared statements. These can be beneficial, for example with DB specific escaping, even when used only once. use prepare once and use always strategy.

* Use stored procedures when they can be created in a standard manner. Do watch out for DB specific SP definitions that can cause migration headaches, but only if you need to support multiple database types. Sometimes over-engineering is a overhead. Don't do something just because you can think :) . Sometimes keeping the things simple is the most desirable and admirable thing on the earth.

* Even though the jdbc promotes portability, true portability comes from NOT depending on any database specific data types, functions and so on.

* Select only required columns rather than using select * from Tablexyz.

* Always close Statement and ResultSet objects as soon as possible.

* Write modular classes to handle database interaction specifics.

* Work with DatabaseMetaData to get information about database functionality.

* Softcode database specific parameters with, for example, properties files.

* Always catch AND handle database warnings and exceptions. Be sure to check for additional pending exceptions.

* Test your code with debug statements to determine the time it takes to execute your query and so on to help in tuning your code. Also use query plan functionality if available.

* Use proper ( and a single standard if possible ) formats, especially for dates.

* Use proper data types for specific kind of data. For example, store birth date as a date type rather than, say, varchar.

*Last but not the least optimize you queries understand from db point of view how the execution plan would be. Identify the queries which executed frequently and could prove bottlenecks.

and the list goes on :)

0 comments: