The code posted by janarthanan seem to be fine. If you are using MySQL then change the Class.forName to the correct driver. Your IDE can point to the correct driver (Netbeans/Myeclipse etc.)