tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Allistair Crossley" <Allistair.Cross...@QAS.com>
Subject RE: Database connection pooling
Date Wed, 27 Oct 2004 11:24:33 GMT
looks like you are using the 5.0 docs rather than 5.5 

http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-resources-howto.html

   
 <Context ...>
  ...
  <Resource name="jdbc/EmployeeDB" auth="Container"
            type="javax.sql.DataSource" username="dbusername" password="dbpassword"
            driverClassName="org.hsql.jdbcDriver" url="jdbc:HypersonicSQL:database"
            maxActive="8" maxIdle="4"/>
  ...
</Context>

 

Allistair

> -----Original Message-----
> From: Nat Titman [mailto:nat.titman@choosemcs.co.uk]
> Sent: 27 October 2004 12:22
> To: tomcat-user@jakarta.apache.org
> Subject: Database connection pooling
> 
> 
> Hi,
> 
> I'm attempting to integrate database connection pooling into an 
> exisiting JSP-based web application.
> 
> I'm running Tomcat 5.5.2 Server, with J2SE 1.5.0 and a MySQL database 
> (version 11.18) accessed through the com.mysql.jdbc package.
> 
> I've followed MySQL instructions from this page:
> 
> http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasourc
> e-examples-howto.html
> 
> I made the changes to server.xml and the web app's web.xml, changing 
> variables to match the database name, user name and password of the 
> correct database. I ensured the MySQL package was in common/lib/.
> 
> My DAO objects now have constructors of the following form, which was 
> adapted from code found online ('broadband' is the database name):
> 
>    private Connection myConn;
>    private DataSource dataSource;
> 
>    /**
>     *  Constructs the data accessor using the connection pool
>     *
>     *  @exception SQLException thrown for SQL errors
>     */
>    public SearchDAO() throws SQLException {
> 
>      try {
> 
>        // retrieve datasource
>        Context init = new InitialContext();
>        Context ctx = (Context) init.lookup("java:comp/env");
>        dataSource = (DataSource) ctx.lookup("jdbc/broadband");
> 
>        // get connection
>        synchronized (dataSource) {
> 
>            myConn = dataSource.getConnection();
> 
>        }
> 
>      } catch (NamingException ex) {
> 
>        System.err.println(
>          "new SearchDAO: Cannot retrieve 
> java:comp/env/jdbc/broadband: "
>          + ex);
> 
>      } catch (SQLException excep) {
> 
>        System.err.println(
>          "new SearchDAO: Could not get connection: " + excep);
> 
>      } catch (Exception e) {
> 
>        System.err.println("new SearchDAO: " + e);
> 
>        // System.out.println ("In the catch block : ....");
>        //e.printStackTrace();
> 
>      }
> 
>    }
> 
> The constructor throws the following exception:
> 
> org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC 
> driver of class '' for connect URL 'null'
> 
> The connect URL is present in server.xml and is correct for 
> the database.
> 
> My only guess at this point is that the howto document above asks for 
> the Context tag to be added to server.xml between the example close 
> Context and the first open Host tag, however there wasn't an example 
> Context tag in server.xml and there appears to be a 
> context.xml file in 
> the same directory. I'm wondering if Contexts have moved to a 
> different 
> file in a recent version of Tomcat? It's just a wild guess 
> (and I've no 
> idea how to add the Context to context.xml as there's already 
> a Context 
> tag in there and no higher level tag around it).
> 
> Any help would be greatly appreciated. Sorry if I'm wasting your time 
> with an obvious or frequently asked question, I've googled and read 
> quite a few documents, but I think I'm just at the 'stabbing in the 
> dark' point and could do with guru guidance.
> 
> Thanks,
> 
> 
> Nat.
> 
> -- 
> Nat Titman
> Developer
> 
> MitchellConnerSearson
> 3-5 High Pavement
> The Lace Market
> Nottingham  NG1 1HF
> Tel +44 (0)115 959 6455
> Fax +44 (0)115 959 6456
> Direct +44 (0)115 959 6462
> www.choosemcs.co.uk
> 
> Confidentiality: This e-mail and its attachments are intended
> for the above named only and may be confidential. If they have
> come to you in error you must take no action based on them,
> nor must you copy or show them to anyone; please reply to this
> e-mail and highlight the error.
> 
> Security Warning: Please note that this e-mail has been
> created in the knowledge that Internet e-mail is not a 100%
> secure communications medium. We advise that you understand
> and observe this lack of security when e-mailing us.
> 
> Viruses: Although we have taken steps to ensure that this
> e-mail and attachments are free from any virus, we advise that
> in keeping with good computing practice the recipient should
> ensure they are actually virus free.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 


<FONT SIZE=1 FACE="VERDANA,ARIAL" COLOR=BLUE> 
-------------------------------------------------------
QAS Ltd.
Developers of QuickAddress Software
<a href="http://www.qas.com">www.qas.com</a>
Registered in England: No 2582055
Registered in Australia: No 082 851 474
-------------------------------------------------------
</FONT>


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


Mime
View raw message