Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Configuring connection pooling in tomcat

 
Glenny Dsilva
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to configure connection pooling in tomcat 5.0

Gone through the eg. give in the url below

http://jakarta.apache.org/tomcat/tomcat-4.1-doc/printer/jndi-datasource-examples-howto.html#MySQL%20DBCP%20Example

After configuring server.xml and web.xml

The code is below

package foo;

import javax.naming.*;
import javax.sql.*;
import java.sql.*;

public class DBTest {

String foo = "Not Connected";
int bar = -1;

public void init() {
try{
Context ctx = new InitialContext();
if(ctx == null )
throw new Exception("Boom - No Context");

DataSource ds =
(DataSource)ctx.lookup(
"java:comp/env/jdbc/TestDB");

if (ds != null) {
Connection conn = ds.getConnection();

if(conn != null) {
foo = "Got Connection "+conn.toString();
Statement stmt = conn.createStatement();
ResultSet rst =
stmt.executeQuery(
"select id, foo, bar from testdata");
if(rst.next()) {
foo=rst.getString(2);
bar=rst.getInt(3);
}
conn.close();
}
}
}catch(Exception e) {
e.printStackTrace();
}
}

public String getFoo() { return foo; }
public int getBar() { return bar;}
}

I am geting "-1 Not Connected"

pls. help.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glenny,
It's best to keep one topic in one thread.
In your other thread, I gave you a link to the 5.5 JNDI documentation.
Now I can see you're using 5.0.
Your link points to the 4.1 configuration page.

Here is the link to the 5.0 documentation.
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-resources-howto.html

Also, this is a servlets forum.
There is a forum just for Tomcat on this site.
If you ask your configuration questions there, you are much more likely to have it seen by someone who has dealt with the same issue.
 
Glenny Dsilva
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, i'll post it in the right place next time....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic