Skip to main content

JDBC Performance Pointers

Here are a few of the JDBC Performance pointers. Hopefully, there are a lot more, which you may be aware of, but not mentioned here. Care to share them as well?

  • Get database connection from connection pool rather than getting it directly
    Use batch transactions.
  • Choose right isolation level as per your requirement.
  • TRANSACTION_READ_UNCOMMITED gives best performance for concurrent transaction based applications. TRANSACTION_NONE gives best performance for non-concurrent transaction based applications.
  • Your database server may not support all isolation levels, be aware of your database server features.
  • Use PreparedStatement when you execute the same statement more than once.
  • Use CallableStatement when you want result from multiple and complex statements for a single request.
  • Use batch update facility available in Statements.
  • Use batch retrieval facility available in Statements or ResultSet.
  • Set up proper direction for processing rows.
  • Use proper getXXX() methods.
  • Close ResultSet, Statement and Connection whenever you finish your work with them.
  • Write precise SQL queries.
  • Cache read-only and read-mostly tables data.
  • Fetch small amount of data iteratively rather than whole data at once when retrieving large amount of data like searching database etc.
  • Use Type one driver if you don't have a driver for your database. This is a rare situation because all major databases support drivers or you will get a driver from third party vendors.
  • Use Type two driver for two tiered applications to communicate from java client to database that gives better performance than Type1 driver.
  • Use Type three driver to communicate between client and proxy server ( weblogic, websphere etc) for three tiered applications that gives better performance when compared to Type 1 &2 drivers.
  • Use Type four driver for applet to database communication that is two tiered applications and three tiered applications when compared to other drivers.
  • Pass database specific properties like defaultPrefetch if your database supports any of them.

Comments

Anonymous said…
This comment has been removed by a blog administrator.
CARFIELD said…
Hi, would you talk more about "Set up proper direction for processing rows."... not sure what that mean... Do you mean rs.next() is not go to next record but previous record?
Anonymous said…
This comment has been removed by a blog administrator.
Anonymous said…
i Cudn't imagine ppl cracking such PJ's .Cancerian means his Sun Sign is cancer.And about rs.next() ,it definately moves to the next row ,I guess what the author is talking here is scrollable result sets which also has previous() and also seek() I guess

Popular posts from this blog

Installing Bugzilla on Windows

Bugzilla is the Bugs/Issues Tracking Tool from The Mozilla Organization. Version 2.18 is the latest stable release. There are couple of resources which guide a User installing Bugzilla on a Unix/linux machine. However, this entry describes a way to install Bugzilla on a Windows machine (W2K to be precise). This document guides you step by step through the installation process. First, get Administrative access to the machine on which you want to install Bugzilla. It should be a simple step. Usually, Users are given Administrative rights on Windows machine. However, if you dont have, contact your Administrator. Get Bugzilla Then download the Bugzilla from http://bugzilla.org/download.html . There are two ways of gettng it - through CVS or direct downloading the tar file. Remember there are no Zip files. However, any zip utility should be able to untar the Bugzilla. I download the tar file and untarred it using WinZip. I placed the untarred 'bugzilla' directory in my c: drive. So...

JSP Performance Tips

Here are a few tips to improve JSP performance that I have been using. If you have your own listing of the tips, plz share. Disable JSP auto reloading feature. Use thread pool for your JSP engine and define the size of thread pool as per application requirement. Use jspInit() method to cache static data Initialize the 'out' object (implicit object) with proper size in the page directive. Set the content length Give 'false' value to the session in the page directive to avoid session object creation. Flush the data partly Use StringBuffer rather than using + operator when you concatenate multiple strings Use include directive instead of include action when you want to include the child page content in the translation phase. Avoid giving unnecessary scope in the 'useBean' action. Use print() method rather than println() method Use ServletOutputStream instead of JSPWriter to send binary data Minimize code in the synchronized block Do not use custom tags if you do no...

How old are the daughters?

Two MIT math graduates bump into each other at Fairway on the upper west side. They hadn't seen each other in over 20 years. The first grad says to the second: "how have you been?" Second: "Great! I got married and I have three daughters now" First: "Really? how old are they?" Second: "Well, the product of their ages is 72, and the sum of their ages is the same as the number on that building over there.." First: "Right, ok.. oh wait.. hmmmm.., I still don't know" second: "Oh sorry, the oldest one just started to play the piano" First: "Wonderful! my oldest is the same age!" Problem: How old are the daughters?