jsp connectivity thru connection pooling

some body has idea how to connect jsp page to mysql using connection pooling.
it will be great favor if somebody has code
LTIndiaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
mohammedfConnect With a Mentor Commented:
first u need to make a JNDI  resource in ur tomcat server ,, the following XML code will be in server.xml file inside ur server.

then u u can lookup for ur JNDI resource and make ur ordinary work with ur database
here a helpfull website:
http://www.onjava.com/pub/a/onjava/2006/04/19/database-connection-pooling-with-tomcat.html
http://www.crazysquirrel.com/computing/java/connection-pooling.jspx
<Context path="/DBTest" docBase="DBTest"
        debug="5" reloadable="true" crossContext="true">
 
  <Logger className="org.apache.catalina.logger.FileLogger"
             prefix="localhost_DBTest_log." suffix=".txt"
             timestamp="true"/>
 
  <Resource 
type="javax.sql.DataSource"
auth="Container"
name="jdbc/TestDB"
factory="org.apache.commons.dbcp.BasicDataSourceFactory"
maxActive="100"
maxIdle="30"
maxWait="10000"
username=""
password=""
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/oss?autoReconnect=true"
removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true"
/>
 
</Context>
 
////////////////////////////
///connection code
///////////////////////////
  private java.sql.Connection connection;
   private Statement statement;
	try{
   
		javax.naming.Context ctx = new javax.naming.InitialContext();
		javax.sql.DataSource ds = (javax.sql.DataSource )ctx.lookup("java:comp/env/jdbc/TestDB"); 
		connection = ds.getConnection();
 
 
         statement = connection.createStatement();
         	}
         	catch (Exception err) {
        FileWriter file=new FileWriter("c:/error.txt");
        file.write(err.toString());
        file.close();
    }

Open in new window

0
 
adrpoCommented:

Hi,

There is come code and explanation here:
http://dev.mysql.com/tech-resources/articles/connection_pooling_with_connectorj.html

You didn't tell us what application server are you using: Tomcat, etc?
There might be a package in the server that already has this capability.

Cheers,
za-k/
0
 
Ajay-SinghCommented:
0
All Courses

From novice to tech pro — start learning today.