Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring jdbc-pool (tomcat 7)

Tags:

tomcat7

i'm having some problems with tomcat 7 for configuring jdbc-pool : i`ve tried to follow this example: http://www.tomcatexpert.com/blog/2010/04/01/configuring-jdbc-pool-high-concurrency

so i have:

conf/server.xml

 <GlobalNamingResources>
  <Resource type="javax.sql.DataSource"
            name="jdbc/DB"
            factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
            driverClassName="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost:3306/mydb"
            username="user"
            password="password"
/>
 </GlobalNamingResources>

conf/context.xml

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

and when i try to do this:

Context initContext = new InitialContext();
Context envContext  = (Context)initContext.lookup("java:/comp/env");
DataSource datasource = (DataSource)envContext.lookup("jdbc/LocalDB");
Connection con = datasource.getConnection();

i keep getting this error:

javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
 at org.apache.naming.NamingContext.lookup(NamingContext.java:803)
 at org.apache.naming.NamingContext.lookup(NamingContext.java:159)

pls help tnx

like image 694
john Avatar asked Jan 19 '11 19:01

john


People also ask

Where do you configure a database connection pool in Tomcat server?

For configuring the connection pool for SQLServer you need to configure the SQLServer drivers as explained in the Microsoft SQL Server section and put the jar file into the TOMCAT_HOME/lib folder. Note that database name, username and password must be defined directly in the URL.

How does Tomcat JDBC connection pool work?

Tomcat jdbc pool implements the ability retrieve a connection asynchronously, without adding additional threads to the library itself. Tomcat jdbc pool is a Tomcat module, it depends on Tomcat JULI, a simplified logging framework used in Tomcat. Retrieve the underlying connection using the javax. sql.

How do I set up connection pooling?

Click Resources > JDBC > Data Sources > data_source > [Additional Properties] Connection pool properties. Click Resources > JMS->Queue connection factories-> queue_connection_factory ->[Additional Properties] Connection pool.

What is maxIdle in Tomcat?

maxIdle (int) The maximum number of connections that should be kept in the pool at all times. Default value is maxActive:100 Idle connections are checked periodically (if enabled) and connections that been idle for longer than minEvictableIdleTimeMillis will be released. ( also see testWhileIdle) tomcat.


1 Answers

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

replace that name="jdbc/LocalDB" with name="jdbc/DB" in your context.xml and

(DataSource)envContext.lookup("java:/comp/env/jdbc/DB");

[the second line of code is redundant].

like image 85
Henry Avatar answered Sep 25 '22 14:09

Henry