aspose file tools*
The moose likes Tomcat and the fly likes How do I implement Connection Pooling with Tomcat 5.0.2.7 and MySQL 4.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How do I implement Connection Pooling with Tomcat 5.0.2.7 and MySQL 4.1" Watch "How do I implement Connection Pooling with Tomcat 5.0.2.7 and MySQL 4.1" New topic
Author

How do I implement Connection Pooling with Tomcat 5.0.2.7 and MySQL 4.1

Nina Savannah
Ranch Hand

Joined: Oct 15, 2008
Posts: 35
I have decided to simplify my request- - -

Is there anyone who can explain to me in a very simple way how I can implement Connection Pooling with Tomcat 5.0.2.7 and MySQL 4.1.

Step by step, simple and easy - including which files to be modified and where it can be found.

I am a beginner and I dont have much knowledge.

Thank you_
[ October 15, 2008: Message edited by: Summer Breeze ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

The problem is that my jsp page keeps loading endlessly, I am stuck.


This is not what we see. Can we see the JSP code?
Nina Savannah
Ranch Hand

Joined: Oct 15, 2008
Posts: 35
Thank you David, I have edited my request, would you be able to assist with that?
[ October 15, 2008: Message edited by: Summer Breeze ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61601
    
  67

"Summer Breeze", please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61601
    
  67

See the JSP FAQ for info on setting up the JSTL.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

The Tomcat docs also have very good instructions for setting up DBCP, including sample code.
Bhaskar Rao
Greenhorn

Joined: Apr 25, 2005
Posts: 23
Hi,

I had faced a similar issue wherein the method DataSource.getConection() would simply hang forever without any response. My development environment had Tomcat 5.0, Connector/J 5.1.6 and MySQL 4.0.

The problem was with the MySQL connector. The Connector/J version that I used was incompatible with the version of MySQL server. I then used Connector/J 5.0.8 which resolved the problem.

which version of connector/J do you use?

You can find more info here MySQL Connector/J documentation.
Nina Savannah
Ranch Hand

Joined: Oct 15, 2008
Posts: 35
Thank you so much for your help. however, i am going round in circles. i am trying to test my connection with the page below but I am getting an error i have also included after the code. Please assist if you can see where the error is and how it can be solved::

/********THE CODE************/

<%@ page import="java.sql.*,javax.sql.*,javax.naming.*,java.io.*,java.lang.*,java.text.*,java.util.*"%>
<%
package foo;

public class myWeb
{

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/myWeb");

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;}
}

%>
<html>
<head>
<title>WFP Test</title>
</head>
<body>

<%
foo.myWeb tst = new foo.myWeb();
tst.init();
%>

<h2>Results</h2>
Foo <%= tst.getFoo() %><br/>
Bar <%= tst.getBar() %>

</body>
</html>
/*********************The End of Code************************/

/***************************The Error**************************/
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 2 in the jsp file: /myWeb/test.jsp
Generated servlet error:
C:\Tomcat5027\work\Catalina\localhost\_\org\apache\jsp\myWeb\test_jsp.java:52: illegal start of expression
package foo;
^


An error occurred at line: 2 in the jsp file: /myWeb/test.jsp
Generated servlet error:
C:\Tomcat5027\work\Catalina\localhost\_\org\apache\jsp\myWeb\test_jsp.java:58: illegal start of expression
public class myWeb {
^


An error occurred at line: 2 in the jsp file: /myWeb/test.jsp
Generated servlet error:
C:\Tomcat5027\work\Catalina\localhost\_\org\apache\jsp\myWeb\test_jsp.java:58: ';' expected
public class myWeb {

/************************End of Errors***************************/
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61601
    
  67

"Summer Breeze", My request that you change your display name to adhere to JavaRanch standards was not a suggestion. Valid display names are mandatory for participation on the Ranch. Please change your display name as instructed prior to your next post.

Be aware that accounts with invalid display names are disabled.

bear
JavaRanch Sheriff
Nina Savannah
Ranch Hand

Joined: Oct 15, 2008
Posts: 35
Dear Sheriff

I have changed my Display Name, thanks!

Regards

Nina
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Don't package JSPs, and don't declare classes in them either. As a general rule, if you need processing, make a Class, if you need display, use a JSP. Try not to mix.
Nina Savannah
Ranch Hand

Joined: Oct 15, 2008
Posts: 35
I set up connection pooling but however I am getting an error:-

The requested resource (/publications/) is not available.

Below is ALL i did to set up connection pooling. Have I ommitted something or is there an error somewhere?


In C:\Tomcat5027\conf\web.xml

This is what I added -:

<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/publications</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>



In C:\Tomcat5027\conf\server.xml

This is what I added -:

<Context path="/publications" docBase="publications" debug="5" reloadable="true" crossContext="true">

<Resource name="jdbc/publications"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
username="root"
password="root"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:8080/publications?autoReconnect=true"/>

</Context>


Thanks Guys...
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Please make sure you use code tags while posting your code.Unformatted code is difficult to read and results in less response for your post. Read this for more information. You can edit your current post to add code tags by clicking .


SCJP, SCWCD.
|Asking Good Questions|
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I implement Connection Pooling with Tomcat 5.0.2.7 and MySQL 4.1