Saturday, February 14, 2009

Love or something like it...

One fine morning I saw you.
Oh God, I could not believe my eyes nor could my eyes believe me.
You saw me, approached me and gave me a gentle smile,
to give me a live canvas of Monalisa's smile.
You spoke to me, your words coming out like that of a gentle dew,
yet bringing into bloom the fairest thoughts of the world.
And then we became great friends,
You encouraged me to leave my hesitation,
You enchanted me to get my determination,
You enlightened the path from which I drew my inspiration,
You made me stand ahead of others in great position.
But by the time I came to tell you, how much
I love you, it was too late, for, you went away.
Leaving behind memories to stay.
Your memories still linger in my mind,
Your gracious picture spread over my heart,
and I put my thoughts into words to tell you
that I love you forever and ever and ever...

Tuesday, February 3, 2009

Configuring JDBC Datasource in Tomcat 5.0.28 in Eclipse WTP

I use Eclipse WTP for developing Web applications. In my previous post I mentioned that I changed the Database connection pool to use the Weblogic connection pool. The configuration in Weblogic was straightforward and simple, but it posed an issue for me during development because I was not able to configure the Datasource in the Installed Server Runtime in my Eclipse WTP. Either I had to use Reflection to supply the class and modify it between Environment deployments and local deployments or needed to fix the issue with Tomcat Datasource. The error that I was constantly getting was

ERROR DatabaseManager.getConnection - org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
at org.apache.commons.dbcp.BasicDataSource.createDataSource(
at org.apache.commons.dbcp.BasicDataSource.getConnection(
at com.pepsi.bdb.connections.DatabaseManager.getConnection(

Googling the error wasn't very fruitful because it mostly dealt with configuring Datasource in Tomcat directly, but not much information was available on configuring with Eclipse WTP. Also, there were several ways of configuring it mentioned in Serverside website and none seem to work for me. Finally I figured it out today and here is how I did

In Eclipse WTP, expand the configured Server under Servers, you will see a file server.xml. This is a copy of the server.xml file that Eclipse creates for you, but uses the libs from the Tomcat folder you configured. In this file add your Datasource under the tag <GlobalNamingResources> as shown below:

<Environment name="simpleValue" type="java.lang.Integer" value="30"/>
<Resource auth="Container" description="User database that can be updated and saved" name="UserDatabase" type="org.apache.catalina.UserDatabase"/>
<Resource name="myDbPool" type="javax.sql.DataSource"/>
<ResourceParams name="UserDatabase">
<ResourceParams name="myDbPool">
<value>select * from dual</value>

Go to the folder where your server is actually located and place the jar file ojdbc14.jar (for Java 1.4, for lower versions, uses classes12.jar) in the folder %TOMCAT_HOME%\common\lib.

In the server.xml on the Eclipse, place an entry inside the <Context> element of your application that is inside the <Host> element as below:

<Context docBase="myApp" path="/myApp" reloadable="true" source="org.eclipse.jst.j2ee.server:myApp">
<ResourceLink name="myDbPool" global="myDbPool" type="javax.sql.DataSource"/>

That is it. This did the trick for me. For the web.xml entry inside your web application and Java code, refer to my previous post.