Can somebody let me know the difference between following two ways of connection? 1. DriverManager.registerDriver((Driver)Class.forName(JDBCD).newInstance()); 2. Class.forName(jdbcDriver); Is there any specific reason when to use one or other. Thnx Satish
I'll have a go at the second one (ramalingam manonmani) first: what you are probably looking for are JSPs and Servlets if you want to present database information in a web page... Now to the initial question: My preference has always been to use Class.forName("Driver class"). When the class is loaded, its static block (if it has one, and Drivers do have a static block) gets executed. This allows the driver to register itself so that when you ask for a connection, the DriverManager can look to the registered Drivers and get one to return a Connection. I'd imagine you could use the initial version when you had an instance of a driver already but did not load it or do not know how to load it yourself. Two ways in which this may occur is if the driver was streamed from some other site on the internet, or if the driver is not on your classpath and you loaded and instantiated it yourself... Pretty wierd but its possible. As to the difference between Class.forName() and Class.forName().getInstance(), I've always prefered the initial version since it doesn't create a useless object. Then again, if you only ever creating one unused object in your code you're doing well so it isn't too much of a problem. These are just thoughts so I wouldn't take them as fact but hope it helps anyway... Dave.