You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Josh Gooding <jo...@gmail.com> on 2014/02/21 15:49:30 UTC

Issue on configuring Connection Pool and datasource in Tomcat 7.

Man this has been a while since I've reached out to this list, but here it
goes.

I am using Tomcat 7 on Windows 7 64x and trying to configure a datasource
(MySQL DB running on a 2nd box) to use.  I am able to connect from my local
to the remote using the mysql command line, so I do know the database is
reachable.  I have a vanilla server.xml and I'm putting the configuration
in the context.xml.  I've written a class to initialize connection objects
from the datasource.  After this configuration, I did something that I
never do and is bad form, but I wrote a jsp that used the <sql> jstl to do
a test to the database, and it worked, so I thought perfect, the JNDI
lookup must be correct.  Once I switched it over to only be used by the
backend code, I get a SQLException being thrown that says:

DataSource invalid: "java.sql.SQLException: No suitable driver found for
jdbc/dashboard"

While I am not 100% convinced that I need the <ResourceLink> tag in the
context.xml, but it's been pointed out multiple times that it is needed.
 Is there something that I am missing here?  Any advice or help you could
provide would be greatly appreciated.  I do think it's a configuration
issue, but I've been known to be wrong before.

Here is the snippet from my web.xml -

 <resource-ref>
      <description>DB Connection</description>
      <res-ref-name>jdbc/dashboard</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>

Here is my context.xml -

      <ResourceLink type="javax.sql.DataSource" name="jdbc/dashboard"
global="jdbc/DB" />

      <Resource name="jdbc/dashboard" auth="Container"
type="javax.sql.DataSource"
               maxActive="100" maxIdle="30" maxWait="10000"
               username="p05jg" password="testing"
driverClassName="com.mysql.jdbc.Driver"
               url="jdbc:mysql://10.0.48.14:3306/dashboard"
               poolPreparedStatments="true"
               maxOpenPreparedStatements="200"
               removeAbandoned="true" logAbandoned="true"
removeAbaondonedTimeout="300"/>

Here is my method for connection initialization -

 private static Logger logger =
LoggerFactory.getLogger("ConnectionInitializer.class"); private static
final String dbName = "jdbc/DB"; private static final String envName =
"java:/comp/env";

        public static Connection initialize () {

Connection connect = null;
 Context context;
try {
context = new InitialContext();
 DataSource dataSource = (DataSource)context.lookup(dbName);
connect = dataSource.getConnection();
 logger.debug("Connection returns schema: " + connect.getSchema());
} catch (NamingException nEx) {
 logger.error("initialize threw a NamingException:  ", nEx.getMessage());
nEx.printStackTrace();
 return null;
} catch (SQLException sqlEx) {
logger.error("initialize threw a SQLException:  ", sqlEx.getMessage());
 sqlEx.printStackTrace();
return null;
}
 return connect;
}

I have also tried another method for returning a connection object (same
method, just modified)

public static Connection initialize () {

Connection connect = null;
 Context initContext;
Context envContext;
try {
 initContext = new InitialContext();
envContext = (Context)initContext.lookup(dbName);
DataSource dataSource = (DataSource)envContext.lookup(envName + "/" +
dbName);
 connect = dataSource.getConnection();
logger.debug("Connection returns schema: " + connect.getSchema());
 } catch (NamingException nEx) {
logger.error("Uh-oh! - initializeConnection threw a NamingException:  ",
nEx.getMessage());
 logger.error("{} not found!", dbName);
nEx.printStackTrace();
return null;
 } catch (SQLException sqlEx) {
logger.error("Uh-oh - initializeConnection threw a SQLException:  ",
sqlEx.getMessage());
 sqlEx.printStackTrace();
return null;
}
 return connect;
}

Re: Issue on configuring Connection Pool and datasource in Tomcat 7.

Posted by Josh Gooding <jo...@gmail.com>.
On Fri, Feb 21, 2014 at 11:21 AM, Mark Thomas <ma...@apache.org> wrote:

> On 21/02/2014 16:17, Josh Gooding wrote:
> > On Fri, Feb 21, 2014 at 9:59 AM, Mark Thomas <ma...@apache.org> wrote:
> >
> >> On 21/02/2014 14:49, Josh Gooding wrote:
> >>
> >>>  Is there something that I am missing here?
> >>
> >> Where is the JAR containing your JDBC driver?
> >>
> >> Mark
> >>
> >
> >
> > Mark,
> >
> > It's in the WEB-INF/lib directory with all of the other jars I have for
> > this app.  Should this be in the $CATALINA_HOME/lib folder?  I to
> remember
> > at one time that there was an issue with where that jar was put (but I'm
> > not positive). Oh and the tomcat logs are clean as well, except when
> trying
> > to access the webapp.  Startup they are all good.
>
> Yes, the JDBC driver needs to be in $CATALINA_[BASE|HOME]/lib.
>
> This requirement no longer exists for 8.0.x.
>
> Mark
>
>
> ---------------------------------------------------------------------
>

Mark,

I'm only using TC7, not 8 yet.

Re: Issue on configuring Connection Pool and datasource in Tomcat 7.

Posted by Mark Thomas <ma...@apache.org>.
On 21/02/2014 16:17, Josh Gooding wrote:
> On Fri, Feb 21, 2014 at 9:59 AM, Mark Thomas <ma...@apache.org> wrote:
> 
>> On 21/02/2014 14:49, Josh Gooding wrote:
>>
>>>  Is there something that I am missing here?
>>
>> Where is the JAR containing your JDBC driver?
>>
>> Mark
>>
> 
> 
> Mark,
> 
> It's in the WEB-INF/lib directory with all of the other jars I have for
> this app.  Should this be in the $CATALINA_HOME/lib folder?  I to remember
> at one time that there was an issue with where that jar was put (but I'm
> not positive). Oh and the tomcat logs are clean as well, except when trying
> to access the webapp.  Startup they are all good.

Yes, the JDBC driver needs to be in $CATALINA_[BASE|HOME]/lib.

This requirement no longer exists for 8.0.x.

Mark


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


Re: Issue on configuring Connection Pool and datasource in Tomcat 7.

Posted by Josh Gooding <jo...@gmail.com>.
On Fri, Feb 21, 2014 at 9:59 AM, Mark Thomas <ma...@apache.org> wrote:

> On 21/02/2014 14:49, Josh Gooding wrote:
>
> >  Is there something that I am missing here?
>
> Where is the JAR containing your JDBC driver?
>
> Mark
>


Mark,

It's in the WEB-INF/lib directory with all of the other jars I have for
this app.  Should this be in the $CATALINA_HOME/lib folder?  I to remember
at one time that there was an issue with where that jar was put (but I'm
not positive). Oh and the tomcat logs are clean as well, except when trying
to access the webapp.  Startup they are all good.

Re: Issue on configuring Connection Pool and datasource in Tomcat 7.

Posted by Mark Thomas <ma...@apache.org>.
On 21/02/2014 14:49, Josh Gooding wrote:

>  Is there something that I am missing here?

Where is the JAR containing your JDBC driver?

Mark

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