File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Configuring connection pooling in tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Configuring connection pooling in tomcat" Watch "Configuring connection pooling in tomcat" New topic
Author

Configuring connection pooling in tomcat

Glenny Dsilva
Ranch Hand

Joined: May 09, 2005
Posts: 42
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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Glenny Dsilva
Ranch Hand

Joined: May 09, 2005
Posts: 42
Sorry, i'll post it in the right place next time....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Configuring connection pooling in tomcat