Hi.

I'm using Tomcat 5.5.9 and MySQL 5.0.17 and here's what my relavent file
sections look like (I've chaned the real app name to "foo", so notice where
"foo" occurs):

<Resource
name="jdbc/foo"
auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
username="tomcat"
password="xxx"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/foo?autoReconnect=true&amp;noDatetimeStringSync=true&amp;zeroDateTimeBehavior=convertToNull"
maxActive="10"
maxIdle="30"
minIdle="10"
maxWait="20000"
poolPreparedStatements="true"
maxOpenPreparedStatements="0"
removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true"
defaultAutoCommit="true"
defaultReadOnly="false"
defaultTransactionIsolation="REPEATABLE_READ" />

Note that you're missing the "name" and "factory" attributes, but I suspect
"name" is more the culprit.

In my WEB-INF/web.xml, this is the resource section:

<resource-ref>
    <res-ref-name>jdbc/foo</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>


mysql-connector-java-3.1.12-bin.jar is located in the
catalina_home/common/lib dir.


The JSP code would look like this:

InitialContext ic = null;
Connection con = null;
DataSource ds = null;
Statement st = null;
ResultSet rs = null;

try
{
      ic = new InitialContext();
      ds = (DataSource)ic.lookup("java:comp/env/jdbc/foo");
      con = ds.getConnection();
      st = con.createStatement();
      rs = st.executeQuery("select * from users");

      //don't forget to release the resources!
}
catch(Exception e)
{ //do something
}


I hope this helps.
-Bob


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to