File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Tomcat-MySql Connection pooling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Tomcat-MySql Connection pooling" Watch "Tomcat-MySql Connection pooling" New topic

Tomcat-MySql Connection pooling

Jim Smithian

Joined: Sep 21, 2004
Posts: 18

I am doing a project for a graduate course using Tomcat, Servlets and MySql. I want to use connection pooling for access to database. I have some problems in the connection pooling. I am not looking for a quick fix, but I want to understand the concepts of connection pooling, data source, JNDI, name binding etc,. I'd like to know what is context, IninialContext etc.
By understanding these topics I can follow the setup documentation and understand and interpret the error messages.

Can anyone please, explain these things or refer me to some on-line tutorials or books.

Here is part of my code and the error message from invoking the servlet:

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");

DataSource ds = (DataSource) envCtx.lookup("jdbc/Diary ");
Connection conn = ds.getConnection();

Statement s = conn.createStatement();
ResultSet R = s.executeQuery("select * from aTable");

When I run the program I get the following error message:

An exception occured:
Name Diary is not bound in this Context
CLASSPATH :\programfiles\SunJ2EE\jdk\lib\tools.jar;D:\programfiles\jakarta-tomcat-5.0.28\bin\bootstrap.jar

javax.naming.NameNotFoundException: Name Diary is not bound in this Context
at org.apache.naming.NamingContext.lookup(

which I think is because of wrong configuration of Tomcat (server,xml, web.xml etc)


Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Maybe you can post your xml files that define your DataSource. It appears it is kind of like having a file in c:\folder\data\myfile.txt and you are trying to look in c:\data\myfile.txt.



Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: Tomcat-MySql Connection pooling
It's not a secret anymore!