This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Tomcat and the fly likes How Tomcat Works: connection pooling in tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How Tomcat Works: connection pooling in tomcat" Watch "How Tomcat Works: connection pooling in tomcat" New topic
Author

How Tomcat Works: connection pooling in tomcat

Tom Boyce
Greenhorn

Joined: Jul 03, 2003
Posts: 24
Tomcat is something of which I both understand and am mystified by at the same time. It has confounded me and been a breeze! "and she's always a woman to me...."!

I am working on an application in which I want to use Tomcat to manage my connection pooling. I am getting the following error:

javax.servlet.ServletException: Name jdbc is not bound in this Context

here is my server.xml:

<Context path="/FamilyViolence" docBase="roller" debug="0">
<Resource name="jdbc/ywstats" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/ywstats">
<parameter>
<name>driverClassName</name>
<value>org.gjt.mm.mysql.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/ywstats?autoReconnect=true</value>
</parameter>
<parameter><name>maxActive</name><value>25</value></parameter>
<parameter><name>maxWait</name><value>100</value></parameter>
<parameter><name>username</name><value>tboyce</value></parameter>
<parameter><name>password</name><value>4guneyeh</value></parameter>
<parameter><name>factory</name><value>org.apache.commons.dbcp.BasicDataSourceFactory</value></parameter>
</ResourceParams>
</Context>

MY Web.xml file:

<resource-ref>
<res-ref-name>"jdbc/ywstats"</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>


My jsp code:

<%

Vector v_cnty=new Vector();
ResultSet rs_cnty = null;
DataSource pool;

InitialContext intCtx = new InitialContext();
DataSource ds = (DataSource)intCtx.lookup("java:comp/env/jdbc/ywstats");
Connection conn = ds.getConnection();
java.sql.Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select county_name from county_info");

while (rset.next())
{
v_cnty.addElement(rset.getString(0));
}


Any help would be greatly appreciated and I'd, of course, love to win a copy of your book!!!
Angel Dobbs-Sciortino
Ranch Hand

Joined: Sep 10, 2003
Posts: 101
Try removing the quotes around "jdbc/ywstats" in your web.xml file.
Tom Boyce
Greenhorn

Joined: Jul 03, 2003
Posts: 24
Well, progress is sometimes made by getting a different error message!

Un-quoting the datasource produced the following error!

javax.servlet.ServletException: Cannot create JDBC driver of class '' for connect URL 'null', cause: No suitable driver

I am using MySql database and have installed mysql-connector-java-3.1.3-beta-bin.jar in the **".. jakarta-tomcat-5.0.19\webapps\FamilyViolence\WEB-INF\lib" directory. I am using NetBeans 3.6 as my IDE.

I appreciate the assistance on this!!

Tom Boyce
Angel Dobbs-Sciortino
Ranch Hand

Joined: Sep 10, 2003
Posts: 101
Is the lib directory is in your classpath?
Tom Boyce
Greenhorn

Joined: Jul 03, 2003
Posts: 24
Yes, it is in my environment variable classpath. I just saw this error when netbeans runs tomcat:

LifecycleException: Container StandardContext[/FamilyViolence/jsp] has not been started
at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4400)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4298)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1126)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:832)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1126)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:521)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:2345)
at org.apache.catalina.startup.Catalina.start(Catalina.java:594)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
Angel Dobbs-Sciortino
Ranch Hand

Joined: Sep 10, 2003
Posts: 101
Try copying your jar file to common/lib in the tomcat directory. If that fixes it, then it's a classpath issue.
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Step for config Datasource

1. don't forget to copy the JDBC Driver's jar into $CATALINA_HOME/common/lib.

2. server.xml configuration
Configure the JNDI DataSource in Tomcat by adding a declaration for your resource to $CATALINA_HOME/conf/server.xml.

3. web.xml configuration
-config in WEB-INF/web.xml


Reference WEbsite
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-datasource-examples-howto.html#Introduction


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Tom Boyce
Greenhorn

Joined: Jul 03, 2003
Posts: 24
I already attempted putting my jar file in the common/lib directory:

C:\Program Files\NetBeans3.6\jakarta-tomcat-5.0.19\common\lib\mysql-connector-java-3.1.3-beta-bin.jar

My environment classpath is as follows:
.;C:\j2sdk1.4.2_05\lib\tools.jar;%CATALINA_HOME%\common\lib\servlet.jar;c:\javamail-1.3.1\mail.jar;c:\jaf-1.0.1\activation.jar;c:\javamail-1.3.1\lib\imap.jar;c:\javamail-1.3.1\lib\mailapi.jar:c:\javamail-1.3.1\lib\pop3.jar;c:\javamail-1.3.1\lib\smtp.jar;C:\TIBCO\TIBRV\LIB\tibrvj.jar;C:\Program Files\NetBeans3.6\jakarta-tomcat-5.0.19\webapps\FamilyViolence\WEB-INF\lib\mysql-connector-java-3.1.3-beta-bin.jar;C:\j2sdk1.4.2_05\jre\bin;C:\mssqlserver.jar


I have the jar file in the WEB-INF file as well:

C:\Program Files\NetBeans3.6\jakarta-tomcat-5.0.19\webapps\FamilyViolence\WEB-INF\lib\mysql-connector-java-3.1.3-beta-bin.jar


Here is my catalina home variable:

C:\Program Files\NetBeans3.6\jakarta-tomcat-5.0.19

JAVA_Home: C:\j2sdk1.4.2_05


Root Directory for project under NetBeans is:
C:\Program Files\NetBeans3.6\jakarta-tomcat-5.0.19\webapps

Properties of http://localhost:8084/ Home directory:
C:\Program Files\NetBeans3.6\jakarta-tomcat-5.0.19

Base Directory:
C:\Documents and Settings\Administrator\.netbeans\3.6\jakarta-tomcat-5.0.19_base

I am truely at a loss!!!
Angel Dobbs-Sciortino
Ranch Hand

Joined: Sep 10, 2003
Posts: 101
It looks like it should work. Have you tried the latest non-beta jdbc driver instead of the beta version? mysql-connector-java-3.0.15-ga-bin.jar
Tom Boyce
Greenhorn

Joined: Jul 03, 2003
Posts: 24
No, I haven't tried the other jar file, but I have been fooling around with file structure. NetBeans creates an instance of tomcat under docs&settings/.netbeans directory, but it did not have any of the project within, so I copied the project into that directory. I am now getting this error:

StandardServer.await: create[8005]: java.net.BindException: Address already in use: JVM_Bind
java.net.BindException: Address already in use: JVM_Bind

I think I've seen this before, but not sure what I did to fix it. Any ideas?
gayathri sridhar
Greenhorn

Joined: Sep 15, 2004
Posts: 13
Originally posted by Tom Boyce:
[QB]StandardServer.await: create[8005]: java.net.BindException: Address already in use: JVM_Bind
java.net.BindException: Address already in use: JVM_Bind
[QB]



So another tomcat instance is already running?
shut it down and try starting again. Try logging off and then start tomcat. If even taht does not work i think the port at which tomcat binds (guess is specified in the server.xml in tomcat needs to be changed to something different).
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
How to use Tomcat with NetBean
http://tomcatint.netbeans.org/doc/tomcat41_howto.html
http://web.netbeans.org/doc/UsingTomcat.html
Tom Boyce
Greenhorn

Joined: Jul 03, 2003
Posts: 24
Cool, thanks for the links - I'll study on them and see if I can get it running! Changing the classpaths blew out every instance of tomcat I had so that's not going to work.

About instances. I have installed 3 seperate tomcats - one version 4.1 and two version 5.0XX. One of those came pre-packaged with netbeans, the other I needed for a project and has been serving as my main instance. But since I am doing connection pooling, I decided to try and use the instance under Netbeans. I only run one instance at a time!

Netbeans creates yet another version of Tomcat (albeit - truncated) under docsandsettings/.netbeans From what I've read so far, netbeans ignores the classpath in the environment variable and creates it own per project (I like this, just haven't figured out how to use it effectively yet). I am hoping these links you provided will help.

I do appreciate everyones assistance. Please standby while I study up to make another run at it!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How Tomcat Works: connection pooling in tomcat