tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon T <tom...@sydneybluegum.com>
Subject Re: BasicDataSourceFactory and TC 4.1.9
Date Sun, 18 Aug 2002 11:32:53 GMT
Paul,

                I have mysql working ok with mm.mysql-2.0.11-bin.jar 
file in the common/lib
                I am using the jdk1.3.1 with the full tomcat 4.1.19 
installation.
           
                Which JDK are you using?                   

	The context web.xml needs to be updated for the context in the server.xml 
	e.g in the tomcat example they created DBTest  <Context path="/DBTest" docBase="DBTest"

                   
                A jsp example that i used for testing
               
                            
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#e0a0e0">
<%@page language="java" import="javax.sql.*"%>
<%@page import="javax.naming.*" %>
<%@page import="java.util.*" %>
<%@page import="java.sql.*" %>
<%
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource)envCtx.lookup("jdbc/mysql");
Connection conn = ds.getConnection();
Statement StatementRecordset1 = conn.createStatement();
ResultSet Recordset1 = StatementRecordset1.executeQuery("select * from 
abc");
boolean Recordset1_isEmpty = !Recordset1.next();
boolean Recordset1_hasData = !Recordset1_isEmpty;
int Recordset1_numRows = 0;
int Repeat1__numRows = 100 ;
int Repeat1__index = 0 ;
Recordset1_numRows += Repeat1__numRows;
%>
<table BORDER=2>
<% while ((Recordset1_hasData)&&(Repeat1__numRows-- != 0))
{
%>
        <tr>
          <td><%= (String) Recordset1.getObject("name") %></td>
        </tr>
        <%Repeat1__index++;
Recordset1_hasData = Recordset1.next();}
Recordset1.close();
conn.close();
%>
</table>
</body></html


Regards,
Simon

Paul McGovern wrote:

>I am having probelms getting a Connection from the DataSource I get out of 
>JNDI. I set up the Resource section of my server.xml as described in the 
>HOW-TO for 4.1.9 and am using mm.mysql 2.0.14 with MySQL 3.23.51. The DB and 
>dirver seem to work fine together.
>
>It seems I can get the DataSource from the JNDI context as expected, but 
>calling getConnection() yeilds an SQLException that says, "Cannot load JDBC 
>driver class 'null'". The driver is sitting in common/lib and can be seen and 
>used by servlets in my context if I do it 'by hand'. A quick look through 
>DBCP's BasicDataSourceFactory confirms 'driverClassName' is the correct 
>parameter name for the driver class, and the exception is being generated in 
>BasicDataSource:
>
>        // Load the JDBC driver class
>        Class driverClass = null;
>        try {
>            driverClass = Class.forName(driverClassName);
>        } catch (Throwable t) {
>            String message = "Cannot load JDBC driver class '" +
>                driverClassName + "'";
>            logWriter.println(message);
>            t.printStackTrace(logWriter);
>            throw new SQLException(message);
>        }
>
>Any help would be greatly appreciated.
>
>
>>>From my server.xml:
><Resource name="jdbc/form_rev_DB" auth="Container" 
>type="javax.sql.DataSource"/>
> <ResourceParams name="jdbc/form_rev_DB">
> <parameter>
>  <name>factory</name>
>  <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
></parameter>
>   <parameter><name>maxActive</name><value>100</value></parameter>
>   <parameter><name>maxIdle</name><value>30000</value></parameter>
>   <parameter><name>maxWait</name><value>100</value></parameter>
>   <parameter><name>username</name><value>tcuser</value></parameter>
>   <parameter><name>password</name><value>XXXXX</value></parameter>
>   <parameter>
>     <name>driverClassName</name>
>     <value>org.gjt.mm.mysql.Driver</value>
>   </parameter>
>  <parameter>
>    <name>url</name>
>    <value>jdbc:mysql://localhost:3306/form_rev</value>
>  </parameter>
></ResourceParams>
>
>>>From my web.xml:
>  <resource-ref>
>      <description>DB Connection</description>
>      <res-ref-name>jdbc/form_rev_DB</res-ref-name>
>      <res-type>javax.sql.DataSource</res-type>
>      <res-auth>Container</res-auth>
>  </resource-ref>
>
>--
>To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
>For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>
>
>
>  
>




--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message