This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi , You can use the following of course if you are having a App Server in place: import javax.sql.*; import javax.naming.*; ..... ....... and within method Hashtable ht = new Hashtable(); ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory"); ht.put(Context.PROVIDER_URL,"t3://localhost:7001"); InitialContext ictx = new InitialContextFactory(ht); DataSource ds = (DataSource)ictx.lookup("some_jdbc_connection_pool_in_server"); Connection cn = ds.getConnection(); ......... then as usual whatever you want to do with connection .............. Hope this serves your need Regards K.Muthukumaran
The user in the thread linked imports the driver and then does the equivalent thing to Class.forName(), except that their code is now hard-coded to the Driver class. Changing database DRivers requires them to recompile their code.
If you've every seen applications like Jira (bug tracking) and a whole bunch of others including anything that accesses a database a wondered 'How do they have code that can change databases so easily?', the answer is using either Class.forName() or a DataSource to make your code independent of the dtaabase type and Driver type.
You can also use the jdbc.drivers property to register a driver to the DriverManager e.g java -Djdbc.drivers=drivers MyProgram. Then you can skip the Class.forName("driver") since the driver will already be registered in the DriverManager.
Joined: Oct 11, 2005
Thanks, I got it
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com