Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Nina Savannah
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64975
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Summer Breeze", please check your private messages for an important administrative matter.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64975
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the JSP FAQ for info on setting up the JSTL.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Tomcat docs also have very good instructions for setting up DBCP, including sample code.
 
Bhaskar Rao
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64975
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Sheriff

I have changed my Display Name, thanks!

Regards

Nina
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic