• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Can't use MySQL connection pool?

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I write two javabean in the package "lyo.bbs.xml...".I works well if I don't use MySQL ConnectionPool.But the jsp compiler report error if I use MySQL ConnectionPool in javabean.
One of my javabean is:"
....... ...... ....... ........
ResultSet rs = null;
Statement stm = null;
Connection conn = null;
String sql = "select * from problem";
//String url = "jdbc:mysql://localhost:3306/test";
public ReadData(){
try{
Context ctx=new InitialContext(); <------If I use it jsp report error
DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/mysql");
conn=ds.getConnection();
stm=conn.createStatement();
rs=stm.executeQuery(sql);
}catch(Exception e){
System.out.println(e.toString());
}
}
public List readD(){
List booklist=new ArrayList();
Readxml readbean=null;
try{
while(rs.next()){
readbean=new Readxml();
readbean.setId(rs.getInt("id"));
readbean.setName(rs.getString("name"));
readbean.setTitle(rs.getString("title"));
readbean.setContent(rs.getString("content"));
readbean.setTime(rs.getString("time"));
booklist.add(readbean);
}"
. ....... ........... ........... ....... ................
////////////////second javabean/////////////
............ ........ .......... ......... .....................
public void setId(int id){
this.id=id;
}
public int getId(){
return this.id;
}
.............. .........getter and setter method............. ...........
. ........... .............. ............... ..............
public Element getXml(Document doc){
Element root=doc.createElement("guestbook");

NumberFormat idformat=NumberFormat.getCurrencyInstance(Locale.US);
Element temp=doc.createElement("id");
temp.appendChild(doc.createTextNode(idformat.format(this.getId())));
root.appendChild(temp);

temp=doc.createElement("name");
temp.appendChild(doc.createTextNode(this.getName()));
root.appendChild(temp);

temp=doc.createElement("Title");
temp.appendChild(doc.createTextNode(this.getTitle()));
root.appendChild(temp);

temp=doc.createElement("content");
temp.appendChild(doc.createTextNode(this.getContent()));
root.appendChild(temp);

temp=doc.createElement("time");
temp.appendChild(doc.createTextNode(this.getTime()));
root.appendChild(temp);
return root;
//////////////////////////////End code///////////
My jsp file is:
<%@page contentType="text/html;charset=gb2312" import="lyo.bbs.xml.*,java.util.*"%>
<html>
<body>
<%
Readxml readbean;
ReadData data=new ReadData();
List list=data.readD();
Iterator iter=list.iterator();
%>
<table border="1" bgcolor="#cceeee">
<tr>
<td>Topic</td><td>Name</td><td>Post time</td>
</tr>
<%
while(iter.hasNext()){
readbean=(Readxml)iter.next();
%>
<tr>
<td><a href="showtitle.jsp?id=<%=readbean.getId()%>"><%=readbean.getTitle()%></a></td>
<td><%=readbean.getName()%></td>
<td><%=readbean.getTime()%></td>
///////////////////error is:////////////////
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 6 in the jsp file: /showtopic.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\tomcat\work\Standalone\localhost\bbs\showtopic_jsp.java:7: package lyo.bbs.xml does not exist
import lyo.bbs.xml.*;
^
C:\tomcat\work\Standalone\localhost\bbs\showtopic_jsp.java:51: cannot resolve symbol
symbol : class Readxml
location: class org.apache.jsp.showtopic_jsp
Readxml readbean;
^
An error occurred at line: 6 in the jsp file: /showtopic.jsp
Generated servlet error:
C:\tomcat\work\Standalone\localhost\bbs\showtopic_jsp.java:52: cannot resolve symbol
symbol : class ReadData
location: class org.apache.jsp.showtopic_jsp
ReadData data=new ReadData();
^
An error occurred at line: 6 in the jsp file: /showtopic.jsp
Generated servlet error:
C:\tomcat\work\Standalone\localhost\bbs\showtopic_jsp.java:52: cannot resolve symbol
symbol : class ReadData
location: class org.apache.jsp.showtopic_jsp
ReadData data=new ReadData();
^
An error occurred at line: 16 in the jsp file: /showtopic.jsp
Generated servlet error:
C:\tomcat\work\Standalone\localhost\bbs\showtopic_jsp.java:68: cannot resolve symbol
symbol : class Readxml
location: class org.apache.jsp.showtopic_jsp
readbean=(Readxml)iter.next();
^
//////////////////End error//////////////////////
But I have the package lyo.bbs.xml.. really.If I don't use MySQL Pool (java:comp/env/jdbc/mysql)it can work property.
I add the content in the server.xml and I registe in mysql console.
/////////////////////////////server.xml//////////
<Context className="org.apache.catalina.core.StandardContext" cachingAllowed="true" charsetMapperClass="org.apache.catalina.util.CharsetMapper" cookies="true" crossContext="false" debug="0" displayName="Welcome to Tomcat" docBase="C:\tomcat\webapps\ROOT\bbs" mapperClass="org.apache.catalina.core.StandardContextMapper" path="/bbs" privileged="false" reloadable="false" swallowOutput="false" useNaming="true" wrapperClass="org.apache.catalina.core.StandardWrapper">
<Resource auth="Container" description="mysql BBS XML Testing " name="jdbc/mysql" scope="Shareable" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/mysql">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/test</value>
</parameter>
<parameter>
<name>password</name>
<value>qijiashe</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>4</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>org.gjt.mm.mysql.Driver</value>
</parameter>
<parameter>
<name>username</name>
<value>lyo</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
</ResourceParams>
<ResourceLink global="jdbc/mysql" name="jdbc/mysql" type="javax.sql.DataSource"/>
</Context>
////////////////////////////////////////////////
Anyone can help me? :roll:
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see the package declaration
package lyo.bbs.xml;
in the source for either of your beans. And are the .class files for those beans where they belong -- WEB-INF/classes/lyo/bbs/xml/ ?
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ron:
Sorry.I write small code for brief.My code is:
///////////////ReadData.java/////////////////////
package lyo.bbs.xml;
import java.sql.*;
import java.io.*;
import java.util.List;
import java.util.ArrayList;
import javax.naming.*;
import javax.sql.DataSource;
public class ReadData{
ResultSet rs = null;
Statement stm = null;
Connection conn = null;
String sql = "select * from problem";
//String url = "jdbc:mysql://localhost:3306/test";
public ReadData(){
try{
Context ctx=new InitialContext();
DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/mysql");
conn=ds.getConnection();
stm=conn.createStatement();
rs=stm.executeQuery(sql);
}catch(Exception e){
System.out.println(e.toString());
}
}
public List readD(){
List booklist=new ArrayList();
Readxml readbean=null;
try{
while(rs.next()){
readbean=new Readxml();
readbean.setId(rs.getInt("id"));
readbean.setName(rs.getString("name"));
readbean.setTitle(rs.getString("title"));
readbean.setContent(rs.getString("content"));
readbean.setTime(rs.getString("time"));
booklist.add(readbean);
}

}catch(Exception ro){
System.out.println(ro.toString());
}
return booklist;
}
}
////////////////Readxml.java///////////////////
package lyo.bbs.xml;
import java.text.NumberFormat;
import java.util.Locale;
import org.w3c.dom.*;
public class Readxml{
private int id = 0;
private String name = null;
private String title = null;
private String content = null;
private String time = null;
public void setId(int id) {
// TODO: Add your code here
this.id=id;
}
public String getName() {
// TODO: Add your code here
return this.name;
}
public String getTitle() {
// TODO: Add your code here
return this.title;
}
public String getContent() {
// TODO: Add your code here
return this.content;
}
public String getTime() {
// TODO: Add your code here
return this.time;
}
public int getId() {
// TODO: Add your code here
return this.id;
}
public void setTitle(String title) {
// TODO: Add your code here
this.title=title;
}
public void setContent(String content) {
// TODO: Add your code here
this.content=content;
}
public void setName(String name) {
// TODO: Add your code here
this.name=name;
}
public void setTime(String time) {
// TODO: Add your code here
this.time=time;
}
public Element getXml(Document doc){
Element root=doc.createElement("guestbook");

NumberFormat idformat=NumberFormat.getCurrencyInstance(Locale.US);
Element temp=doc.createElement("id");
temp.appendChild(doc.createTextNode(idformat.format(this.getId())));
root.appendChild(temp);

temp=doc.createElement("name");
temp.appendChild(doc.createTextNode(this.getName()));
root.appendChild(temp);

temp=doc.createElement("Title");
temp.appendChild(doc.createTextNode(this.getTitle()));
root.appendChild(temp);

temp=doc.createElement("content");
temp.appendChild(doc.createTextNode(this.getContent()));
root.appendChild(temp);

temp=doc.createElement("time");
temp.appendChild(doc.createTextNode(this.getTime()));
root.appendChild(temp);
return root;
}
}
///////////////////////End javabean////////////
They are all in C:\tomcat\webapps\ROOT\WEB-INF\classes
The important things is that the jsp page can work property if I don't use MySQL ConnectionPool.
And I test it under the Weblogic6.1.I also use Weblogic Connection Pool and it works well.Is MySQL' problem? :roll:
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are in \tomcat\webapps\ROOT\WEB-INF\classes ?
They need to be in \tomcat\webapps\ROOT\WEB-INF\classes\lyo\bbs\xml .
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ron:
I means the package "lyo" is in the C:\tomcat\webapps\ROOT\WEB-INF\classes.
The lyo.bbs.xml is exactly in the "C:\tomcat\webapps\ROOT\WEB-INF\classes\lyo\bbs\xml". Why it can works property in weblogic6.1' Connection Pool? :roll:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!