?
Solved

Deploying c3p0 Pooling Manager

Posted on 2011-05-09
12
Medium Priority
?
751 Views
Last Modified: 2012-05-11
I cut and pasted some code from a Tomcat 6 book.


<h1>JDBC Test - Direct C3P0</h1>
<%!
private static ComboPooledDataSource pool;
public void jspInit() {
try {
pool = new ComboPooledDataSource();
pool.setDriverClass( “com.mysql.jdbc.Driver” );
pool.setJdbcUrl( “jdbc:mysql://localhost:3306/wroxtomcat?autoReconnect=true” );
pool.setUser(“empro”);
pool.setPassword(“empass”);
pool.setAcquireIncrement(3);
pool.setMaxPoolSize(30);
} catch (Exception ex) {
// JSP init() cannot throw any exception ex.printStackTrace();
}
}
%>


I get compile diagnostics:



type Exception report

message

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

exception

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 4 in the jsp file: /jsp/wroxjdbc/CP30Test.jsp
ComboPooledDataSource cannot be resolved to a type
1:
2: <h1>JDBC Test - Direct C3P0</h1>
3: <%!
4: private static ComboPooledDataSource pool;
5: public void jspInit()
6:  {
7: try {


An error occurred at line: 8 in the jsp file: /jsp/wroxjdbc/CP30Test.jsp
pool cannot be resolved
5: public void jspInit()
6:  {
7: try {
8: pool = new ComboPooledDataSource();
9: pool.setDriverClass( "com.mysql.jdbc.Driver" );
10: pool.setJdbcUrl( "jdbc:mysql://localhost:3306/test?autoReconnect=true" );
11: pool.setUser("empro");

I'm assuming the author successfully compiled the code.  Any Idea why " pool cannot be resolved"??
0
Comment
Question by:xoxomos
  • 6
  • 6
12 Comments
 
LVL 92

Accepted Solution

by:
objects earned 1000 total points
ID: 35725127
you need to add the required imports to the top of your file
0
 
LVL 92

Expert Comment

by:objects
ID: 35725135
<%@ page import="com.mchange.v2.c3p0.ComboPooledDataSource" %>
0
 

Author Comment

by:xoxomos
ID: 35731949
Thanks objects.  I was thinking it would be something like that, but had no clue what.  That did not resolve the problem yet though.

type Exception report

message

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

exception

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 6 in the generated java file
Only a type can be imported. com.mchange.v2.c3p0.ComboPooledDataSource resolves to a package

An error occurred at line: 10 in the jsp file: /jsp/wroxjdbc/CP30Test.jsp
ComboPooledDataSource cannot be resolved to a type
7:
8: <h1>JDBC Test - Direct C3P0</h1>
9: <%!
10: private static ComboPooledDataSource pool;
11: public void jspInit()
12:  {
13: try {


An error occurred at line: 14 in the jsp file: /jsp/wroxjdbc/CP30Test.jsp
pool cannot be resolved
11: public void jspInit()
12:  {
13: try {
14: pool = new ComboPooledDataSource();
15: pool.setDriverClass( "com.mysql.jdbc.Driver" );
16: pool.setJdbcUrl( "jdbc:mysql://localhost:3306/test?autoReconnect=true" );
17: pool.setUser("empro");
********************************************************************************************************************


<%@ page import="com.mchange.v2.c3p0.ComboPooledDataSource" %>
<h1>JDBC Test - Direct C3P0</h1>
<%!
private static ComboPooledDataSource pool;
public void jspInit()
 {
try {
pool = new ComboPooledDataSource();
pool.setDriverClass( "com.mysql.jdbc.Driver" );
pool.setJdbcUrl( "jdbc:mysql://localhost:3306/test?autoReconnect=true" );
pool.setUser("empro");
pool.setPassword("empass");
pool.setAcquireIncrement(3);
pool.setMaxPoolSize(30);
}
catch (Exception ex)
 {
// JSP init() cannot throw any exception ex.printStackTrace();
}
}
%>

<%
Connection conn= pool.getConnection();
Statement stmt= conn.createStatement();
ResultSet rset= stmt.executeQuery("select * from employee;");
%>
<table width='600' border='1'>
<tr>
<th align='left'>Employee ID</th>
<th align='left'>Name</th>
<th align='left'>Department</th>
</tr>
<%
while (rset.next()) {
%>
<tr><td> <%= rset.getString(1) %></td>
<td> <%= rset.getString(2) %></td>
<td> <%= rset.getString(4) %></td>
</tr>
<% }
if (stmt != null)
stmt.close();
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 92

Expert Comment

by:objects
ID: 35733516
strange error, make sure you don't have a directory named hComboPooledDataSource somewhere in your app
0
 

Author Comment

by:xoxomos
ID: 35742260
Nope.  I put a c3p0-0.9.1 in the %CATALINA_HOME%/lib directory.
0
 

Author Comment

by:xoxomos
ID: 35742355
I'm not convinced this book is error free.  For instance it say copy the jsp as :


The JSP that you create is placed in the %CATALINA_HOME%/webapps/examples/jsp/wroxjdbc
directory. The file is called C3P0Test.jsp

....but then the URL is
http://localhost:8080/examples/jsp/wroxjdbc/CP30Test.jsp

and there is no CP30Test.jsp
0
 

Author Comment

by:xoxomos
ID: 35742555
Objects!  Long time :-)
I needed to add something in this line, i think probably the java.net
<%@ page import="java.net.*, java.io.*, java.sql.*, java.util.*"%>
0
 
LVL 92

Expert Comment

by:objects
ID: 35742567
its the java.sql you needed, but not for the error you were asking about in the question
for that you needed what I suggested
0
 
LVL 92

Expert Comment

by:objects
ID: 35742572
And your question didn't even show that you were using java.sql class so its a bit hard for me to work that out
0
 

Author Comment

by:xoxomos
ID: 35742692
The points should go to objects.  The answer was in his very first comment which I overlooked.
0
 

Author Comment

by:xoxomos
ID: 35742729
Yeah, i don't understand java so for sure i don't understand this.  Now I've commented out those lines at the top

//

//<%@ page import="java.net.*, java.io.*, java.sql.*, java.util.*"%>

//<%@ page import="com.mchange.v2.c3p0.ComboPooledDataSource" %>
saved the modified jap and it still works!!!!????
0
 
LVL 92

Expert Comment

by:objects
ID: 35742829
could be running the old class file, though it should be doing a recompilation
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month17 days, 1 hour left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question