datasource - Try to make a Connection Pool with Tomcat 6 -
i having nightmare configuring tomcat set connection pool. have done lot of reading of various forums , documents tomcat having ask here last resort. first time have tried connections container it's new me.
i have been having namenotfoundexception's seem fixed when put context.xml file myapp/meta-inf/context.xml tomcat 6.0/conf/context.xml, reason it's not seeing context.xml file in myapp's meta-inf directory. ideas?
now getting sqlnestedexception: cannot create poolableconnectionfactory (''@'localhost' (using password:yes))
first of suprises me user blank because have specified 'root' in context.xml. not being able create poolableconnectionfactory, have seen couple of example context.xml files had factory attribute. need this? if class should specify there?
my context.xml is:
<?xml version='1.0' encoding='utf-8'?> <context> <!-- configure jdbc datasource user database --> <resource name="jdbc/searchdb" type="javax.sql.datasource" auth="container" user="root" password="mypassword" driverclassname="com.mysql.jdbc.driver" url="jdbc:mysql://localhost:3306/search" maxactive="8" maxidle="4"/> <!-- default set of monitored resources --> <watchedresource>web-inf/web.xml</watchedresource> <!--<watchedresource>meta-inf/context.xml</watchedresource>--> </context>
i have seen context.xml watchedresource elemnt meta-inf/context.xml. tried didn't seem make difference , seems strange me have commented out. should including it?
my test servlet:
package search.web; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; import java.sql.*; import javax.sql.*; import javax.naming.*; import search.model.*; public class conpooltest extends httpservlet { public void doget(httpservletrequest request, httpservletresponse response) throws ioexception, servletexception { context ctx = null; datasource ds = null; connection conn = null; try { ctx = new initialcontext(); ds = (datasource)ctx.lookup("java:comp/env/jdbc/searchdb"); conn = ds.getconnection(); if(conn != null) { system.out.println("have connection pool"); } } catch(sqlexception e) { e.printstacktrace(); } catch(namingexception e) { e.printstacktrace(); } { try { if(conn!=null) { conn.close(); } } catch(sqlexception e) { e.printstacktrace(); } } } }
i forward suggestions.
many thanks
joe
ps have listed stack trace, reason showing in console, not in logs.
update:
now @ error message again i'm wondering is denying me access. assumed database, itactually container? need set sort of authentication in tomcatusers.xml file?
the tomcat docs jndi datasources contain complete examples how setup jdbc data sources in context.xml
some comments question:
tomcat should copy
context.xml
app's warconf/catalina/localhost/app.xml
during deployment (when unpacks app). file should not goconf/
. check whether have old copy lying around in these places , clean up.the error it's using wrong user suggests there more single
context.xml
, you're looking @ wrong one.you don't need
poolableconnectionfactory
tomcat 6. might cruft left update tomcat 5 or broke , tried several things , forgot clean config file.tomcat automatically watches
web.xml
; there no need makewatchedresource
second time.
Comments
Post a Comment