Tomcat JNDI configuration - Mailing list pgsql-jdbc

From Wojciech Michalik
Subject Tomcat JNDI configuration
Date
Msg-id 1129491053.6734.14.camel@localhost.localdomain
Whole thread Raw
Responses Re: Tomcat JNDI configuration
List pgsql-jdbc
I am using Tomcat (5.5.9|| 5.5.7) and 7.4 database version. In my
application I am trying to create DBCP. Still getting this error:
javax.servlet.ServletException: Unable to get connection, DataSource
invalid: "java.sql.SQLException: No suitable driver

Newest driver is in $TOMCAT_HOME/common/libs/
When I try to use the database through normal connection everything
works fine:
<sql:setDataSource var="my_data_source" driver="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/prac_samp_jsp" user="pingwin"
password="pingwinek_-_"/>
<sql:query var="empList" scope="request" dataSource="${my_data_source}"
>
  SELECT * FROM Employee
    WHERE FirstName LIKE ?
      AND LastName LIKE ?
      AND Dept LIKE ?
    ORDER BY LastName
  <sql:param value="%${param.firstName}%" />
  <sql:param value="%${param.lastName}%" />
  <sql:param value="%${param.dept}%" />
</sql:query>

Piece of code from jsp page causing this error is:
<sql:query var="empList" scope="request">
I do not specify any connection parameters  here.
my aproprite web.xml piece:
<resource-ref>
    <description>
      JNDI DataSource for example database
    </description>
    <res-ref-name>jdbc/Sample_JSPBook</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Sharable</res-sharing-scope>
  </resource-ref>
  <context-param>
    <param-name>javax.servlet.jsp.jstl.sql.dataSource</param-name>
    <param-value>jdbc/JSP_Book</param-value>
  </context-param>

In server.xml it looks like this:
<Resource name="jdbc/JSP_Book" auth="Container"
          type="javax.sql.DataSource" />
 <ResourceParams name="jdbc/JSP_Book">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>org.postgresql.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:postgresql:prac_samp_jsp://localhost:5432/prac_samp_jsp</value>
</parameter>
<parameter>
<name>username</name> <!--Dont forget to change the realm
username/password to-->
<value>myusername</value>
</parameter>
<parameter>
<name>password</name>
<value>mypassword</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>25</value>
</parameter>
<!-- Maximum number of idle dB connections to retain in pool.
Set to 0 for no limit.
-->
<parameter>
<name>maxIdle</name>
<value>0</value>
</parameter>
<!-- Maximum time to wait for a dB connection to become available
in ms, in this example 10 seconds. An Exception is thrown if
this timeout is exceeded. Set to -1 to wait indefinitely.
-->
<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>
<!-- To configure a DBCP DataSource so that abandoned dB connections are
removed and
recycled add the following paramater to the ResourceParams configuration
for your DBCP
DataSource Resource: -->
<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>
<!--Use the removeAbandonedTimeout parameter to set the number of
seconds a dB connection has been idle before it is considered abandoned.
-->
<parameter>
<name>removeAbandonedTimeout</name>
<value>600</value> <!--Wait 3 hour before statuating a connection is
abandoned-->
</parameter>

<!-- The logAbandoned parameter can be set to true if you want DBCP to
log a stack trace
of the code which abandoned the dB connection resources. -->

       <parameter>
           <name>logAbandoned</name>
           <value>true</value>
       </parameter>



</ResourceParams>



pgsql-jdbc by date:

Previous
From: Gianluca Maiolini
Date:
Subject: unsuscribe
Next
From: Tom Arthurs
Date:
Subject: Re: Tomcat JNDI configuration