tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Carlos Puero C." <cpu...@cuenca.gov.ec>
Subject [Fwd: Re: [Fwd: Re: Problems with Tomcat 5.0.28 and Netbeans 5.0]]
Date Fri, 08 Sep 2006 16:31:34 GMT



Hi Martin, thanks 4 ur help, I don't know what I've changed but, I
created a new project, all the pages new, I put the code that u gave
me.... and IT WORKED..... ;-)

I was very tired but al least it
works... thank y very much....

Saludos 
Lsi. Carlos Puero
C. 


---------------------------- Mensaje original
---------------------------- 
Asunto: Re: [Fwd: Re: Problems with
Tomcat 5.0.28 and Netbeans 5.0] 
De: "Martin Grogan"
<mgrogan@keizensoftware.com> 
Fecha: Jue, 7 de Septiembre de
2006, 2:19 pm 
Para: "Tomcat Users List"
<users@tomcat.apache.org> 
--------------------------------------------------------------------------


Carlos, 
I've pasted below some of the settings I use
with my connection pooling 
(using Tomcat 5.5.9) (please note there
is a difference between this and 
some earlier versions of Tomcat -
you will have to refer to the Tomcat 
5.0.28 manual for the
differences in context.xml when setting up 
connection resources).
Also, you are using JSP's which I don't have 
experience with. I've
pasted some servlet code instead. 
I hope this is useful. 
Martin 

------ 
// fragment from web.xml 
<resource-ref> 
<description>DB
Connection</description> 
<res-ref-name>jdbc/dbname</res-ref-name> 
<res-type>javax.sql.DataSource</res-type> 
<res-auth>Container</res-auth> 
</resource-ref>



// context.xml 
<?xml version="1.0"
encoding="UTF-8"?> 
<Context
path="/contextname"> 
<Logger
className="org.apache.catalina.logger.FileLogger" 
prefix="contextname." suffix=".log"
timestamp="true"/> 
<Resource
auth="Container"
driverClassName="com.mysql.jdbc.Driver" 
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"

maxActive="30" maxIdle="10"
maxWait="10000" name="jdbc/dbname" 
password="******" removeAbandoned="true"
removeAbandonedTimeout="60" 
type="javax.sql.DataSource"
url="jdbc:mysql://localhost:3306/database" 
username="user"/> 
</Context> 


// sample servlet 
public class myservlet extends HttpServlet { 
private static DataSource ds=null; 
public void init(ServletConfig
config) throws ServletException { 
try 
{ 
Context ctx =
new InitialContext(); 
this.ds =
(DataSource)ctx.lookup("java:comp/env/jdbc/dbname"); 
} 
catch (Exception e) { e.printStackTrace(); } 
super.init(config);

} 

public void destroy() { 
ds=null; 
} 

protected void processRequest(HttpServletRequest request, 
HttpServletResponse response) 
throws ServletException, IOException
{ 
response.setContentType("text/html;charset=UTF-8"); 
PrintWriter out = response.getWriter(); 
Connection
connection=null; 
try 
{ 
connection=ds.getConnection();

Statement statement = connection.createStatement(); 
// execute
queries here... 
statement.close(); 
connection.close(); 
}

catch(Exception e) { out.println(e.getMessage()); } 
finally {
try{connection.close(); } catch(Exception e) {} } 
out.close(); 
} 
} 



Carlos Puero C. wrote: 
> 
> Hi Martin, thanks for anwering my message. 
> 
>
This is a part 
> of my web.xml, there's nothing interesting in
that 
> 
> <wbe-app> 
>
<welcome-file-list> 
>
<welcome-file>index.jsp</welcome-file> 
>
</welcome-file-list> 
> <resource-ref> 
>
<description>DataSource de 
> MySQL</description> 
> 
> <res-ref-name>jdbc/Mytest</res-ref-name> 
> <res-auth>Container</res-auth> 
> 
>
<res-sharing-scope>Shareable</res-sharing-scope> 
>
</web-app> 
> 
> This is a part of my context.xml, I
guess 
> that here's the problem... 
> 
> <?xml
version="1.0" 
> encoding="UTF-8"?> 
> <Context 
> path="/prueba4"> 
>
<Logger 
>
clasName="org.apache.catalina.logger.FileLogger" 
>
prefix="prueba4." suffix=".log" 
>
timestamp="true"/> 
> <Resource 
>
name="jdbc/Mytest" type="javax.sql.DataSource"/>

> <ResourceParams name="jdbc/Mytest"> 
>
<parameter> 
> 
> <name>url</name> 
> 
>
<value>jdbc:mysql://localhost:3306/test?autoReconnect=true</valure>

> </parameter> 
> 
> <parameter> 
> 
> <name>driverClassName</name> 
> 
> <value>com.mysql.jdbc.Driver</value> 
> 
> </parameter> 
> <parameter> 
>
<name>username</name> 
>
<value>myuser</value> 
> </parameter> 
>

> <parameter> 
> 
>
<name>password</name> 
> 
>
<value>mypass</value> 
> 
> </parameter>

> <parameter> 
> 
>
<name>validationQuery</name> 
> <value>select

> now()</value> 
> </ResourceParams> 
> </Context> 
> 
> This is part of my JSP
(index.jsp) 
> 
> <%@taglib prefix="sql"
uri="http://java.sun.com/jstl/sql"%> 
> <%@taglib

> prefix="c"
uri="http://java.sun.com/jstl/core" 
> %> 
>
<html> 
> <head> 
> <title>JSP
Page</title> 
> 
> </head 
> <body>

> <h1>JSP 
> Page</h1> 
>
<sql:query var="rs" 
>
dataSource="jdbc/Mytest"> 
> 
> select
id_padre, id_hijo from my_hijo 
> 
> </sql:query>

> <table 
> border="1"> 
>
<!-- 
> columm headers --> 
> <tr> 
>
<c:forEach 
> var="columnName"
items="${rs.columnNames}"> 
> 
>
<th><c:out value="${columnName}"/></th> 
> </c:forEach> 
> </tr> 
> <!-- columm
data --> 
> <c:forEach 
> var="row"
itmes="${rs.rowsByIndex}"> 
> <tr> 
>

> <c:forEach var="column"
items="${row}"> 
> 
> <td><c:out
value="${column}"/></td> 
> 
>
</c:forEach> 
> </tr> 
> </c:forEach>

> </table> 
> </body> 
>
</html> 
> 
> I don't really know which is the
problem, I've 
> tried with some solutions but they seem not
work.. 
> 
> Any magic 
> solution....? 
>

> Saludos 
> Lsi. Carlos Puero C. 
>
Guayaquil-Ecuador 
> 
> ----------------------------
Mensaje 
> original ---------------------------- 
>
Asunto: Re: Problems with 
> Tomcat 5.0.28 and Netbeans 5.0 
> 
De: "Martin Grogan" 
>
<mgrogan@keizensoftware.com> 
> Fecha: Mie, 6 de Septiembre
de 
> 2006, 2:14 am 
> Para: "Tomcat Users List"

> <users@tomcat.apache.org> 
>
--------------------------------------------------------------------------

> 
> 
> Hi Carlos, 
> Can you post the
relevant snippets from your 
> web.xml, context.xml and 
>
servlet init() method (where you 
> instansiate the connection
pool)? 
> Martin 
> 
> 
> Carlos 
> Puero C. wrote: 
> 
>> Hi everybody, I got a
problem... And 
>> 
> I'd like your help 
> 
>> I 
>> use NetBeans 5.0 
>> 
>
with Tomcat 5.0.28 and MySQL 5.0.21, I try to crate a 
> 
> connection pool from Tomcat to Mysql, I followed all the steps that
I've 
> 
> 
>> found on similar forums, and my
frustration is that appears an 
>> 
> error: No 
> 
>> Suitable Driver... 
>> 
>> In
the 
>> 
> forums say that it means that my url 
> 
>> of connection is mal 
>> 
>
formed... I try with the same url a test with a 
> 
>>
single class, 
>> 
> calling Class.forName method
and.... The url is ok.... 
> 
>> I put the code of the
configuration of the pool in the files 
>> web.xml and
context.xml, becuase I read that.... but it doesn't 
>> 
> work... 
> 
>> Any suggestion....? 
>> 
>> PD: I put the 
>> 
> MySQL/J
Connector in 
> 
>> TOMCAT_HOME/commos/lib.... 
>> 
>> Thanks a lot... 
>> 
>>

>> 
> 
> 
> 


-- 
------------ 
Martin Grogan 
Keizen Software 

mgrogan@keizensoftware.com 
www.keizensoftware.com 


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

To start a new topic, e-mail: users@tomcat.apache.org 
To
unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org 
For
additional commands, e-mail: users-help@tomcat.apache.org 



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message