• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

connection pooling with tomcat

 
Kelly Crowe
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I am using the netbeans e-commerce tutorial to learn about web development. I am using tomcat instead of glassfish and I've been trying to establish a connection pool with tomcat and MySQL but have not been successful. I've spent hours looking at forums and tutorials but to no avail.

My context.xml code:
<?xml version="1.0" encoding="UTF-8"?>

<Context antiJARLocking="true" path="/OnlineStore">

<resource-ref>
<description>Connection pool to mysql onlinestore database</description>
<res-ref-name>onlinestore</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

</Context>



My web.xml includes the following code:
<resource-ref>
<description>Connection pool to mysql onlinestore database</description>
<res-ref-name>onlinestore</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>


My test file testDataSource.jsp code:
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<sql:query var="result" dataSource="onlinestore">
SELECT * FROM category
</sql:query>


</body>
</html>


Also, I've imported the JSTL 1.1 libraries and the MySQL-connector-java-5.1.18-bin.jar.


I am getting the following error:

HTTP Status 500 - An exception occurred processing JSP page /test/testDataSource.jsp at line 20

--------------------------------------------------------------------------------

type Exception report

message An exception occurred processing JSP page /test/testDataSource.jsp at line 20

description The server encountered an internal error that prevented it from fulfilling this request.

exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /test/testDataSource.jsp at line 20

17: </head>
18: <body>
19: <h1>Hello World!</h1>
20: <sql:query var="result" dataSource="onlinestore">
21: SELECT * FROM category
22: </sql:query>
23:


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)



root cause
javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'"
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
org.apache.jsp.test.testDataSource_jsp._jspService(testDataSource_jsp.java:94)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)



root cause
javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'"
org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(QueryTagSupport.java:285)
org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(QueryTagSupport.java:168)
org.apache.jsp.test.testDataSource_jsp._jspx_meth_sql_005fquery_005f0(testDataSource_jsp.java:116)
org.apache.jsp.test.testDataSource_jsp._jspService(testDataSource_jsp.java:82)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)


Is there anyone out there who can help me or point me in the right direction? It would be very, very much appreciated.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18226
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Kelly!

You can make your code and XML easier to read by using code tags. There's a button on our message editor that will insert them.

It appears that you have attempted to configure a database connection pool with no database attached to it! Check the Tomcat docs for information on setting the pool's JDBC URL, driver class (the driver jar should be copied into the TOMCAT_HOME/lib directory), database connection userid and password.
 
Kelly Crowe
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your response. I went back to the drawing board and took another look at the configuration parameters and now have the following

Context.xml


My web.xml did not change:


I updated my testDataSource.jsp file to the following:



I received the following error when I try to run the testDataSource.jsp file:
org.apache.jasper.JasperException: file:C:/murach/servlet_jsp/netbeans/OnlineStore/build/web/test/testDataSource.jsp(27,16) PWC6038: "${result.columnNames}" contains invalid expression(s): javax.el.ELException: Unable to find ExpressionFactory of type: org.apache.el.ExpressionFactoryImpl
org.apache.jasper.JasperException: : javax.el.ELException: Unable to find ExpressionFactory of type: org.apache.el.ExpressionFactoryImpl
C:/murach/servlet_jsp/netbeans/OnlineStore/build/web/test/testDataSource.jsp(27,16)
C:\murach\servlet_jsp\netbeans\OnlineStore\nbproject\build-impl.xml:913: Java returned: 1
BUILD FAILED (total time: 1 second)


If I am interpreting this correctly, it looks like I can connect to the database because the error is occurring for the output and not the query. However, that being said I'm not sure what I've done wrong in coding the output. I used the Insert DB report dialog box which then auto-generated the output code. This leads me to believe that maybe I am missing a jar file (already have jasper-el and jasper) in my libraries or am missing a taglib but I haven't been able to figure out the issue. Please let me know if you have any suggestions.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18226
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably have a class conflict in the EL processor. Which version of Tomcat are you using?

In Tomcat5, you had to provide your own EL classes in your WAR.

In Tomcat6, EL support was part of Tomcat, and if you included EL classes in your WAR you would have issues.

I haven't taken that close a look at Tomcat 7, but an app built for Tomcat 6 might have some compatibility issues.
 
Kelly Crowe
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Tomcat 7.0.35. Any suggestions on a work around most likely to work?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic