Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Tomcat Users »

DB connection pool problem

Arora, Avinash

2004-05-03

Replies:

Hi,
 I am also having the problem with the connection pools. Since I am
writing an application first time by using connection pools, I created a
test application DBTest. I edited my server.xml and web.xml (of my
application in following way--
#added to server.xml
<Context path="/DBTest" docBase="DBTest" debug="0"
               reloadable="true">
       <ResourceParams name="jdbc/conversion">
          <parameter>
            <name>username</name>
            <value>ROOT</value>
          </parameter>
          <parameter>
            <name>password</name>
            <value>PASSWORD</value>
          </parameter>
          <parameter>
            <name>driverClassName</name>
            <value>com.mysql.jdbc.Driver</value>
          </parameter>
          <parameter>
            <name>url</name>
            <value>jdbc:mysql://localhost/DB</value>
           </parameter>
        </ResourceParams>
      </Context>
   
#web.xml
<web-app>
  <description>MySQL Test App</description>
<resource-ref>
  <res-ref-name>jdbc/conversion</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
</resource-ref>
</web-app>
And I added the following statements to my Java class, (which works
fine, when I use the connection objects by hardcoding the username and
db).--

Context init = new InitialContext();
Context ctx = (Context) init.lookup("java:comp/env");
DataSource dataSource = (DataSource)ctx.lookup("jdbc/conversion");

But even after, making these changes, I cannot read any thing from
database. I was wondering what more changes I need to made. I also tried
to run my JAVA class (DAO) from command line, but I get the following
exception--

Need to specify class name in environment or system property, or as an
applet parameter, or in an application resource file:
java.naming.factory.initial

I tried to print outs the place where exception occurs in my code and
found that exception occurs at
dataSource = (DataSource)ctx.lookup("jdbc/conversion");

Can any body please comment on whats going on wrong? When I run from
command line, is tomcat used, I don't think so? So where is the problem?
Any ideas??
Avinash Arora



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.