This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tomcat-MySql Connection pooling

 
Jim Smithian
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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
Details:

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

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


Thanks.

Jim
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic