You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Fargusson.Alan" <Al...@ftb.ca.gov> on 2007/04/13 00:01:02 UTC

DB2 DataSource.

Can someone point me to documentation on setting up a DataSource to DB2?

I tried to use the examples for Oracle and MySql, but I have not been able to get it to work.

I am able to access DB2 using the DriverManager.

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


RE: DB2 DataSource.

Posted by "Fargusson.Alan" <Al...@ftb.ca.gov>.
I tried the management console way because I was not sure I was getting the xml right.  I will stick with that until I find something wrong with the generated xml.

-----Original Message-----
From: Rashmi Rubdi [mailto:rashmi.sub@gmail.com]
Sent: Friday, April 13, 2007 11:09 AM
To: Tomcat Users List
Subject: Re: DB2 DataSource.


On 4/13/07, Fargusson.Alan <Al...@ftb.ca.gov> wrote:
> I am putting my Resource inside the GlobalNamingResource.  Do I need anything in the Context node?
>

If you are using GlobalNamingResource you don't need the Context node
because it is global to all contexts and not just one context.

> I have been doing this two different ways.  My latest attempts I have used the management > console which generates the server.xml file.

Focus on one way :-) and get it to work before attempting alternatives.

>

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


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


Re: DB2 DataSource.

Posted by Rashmi Rubdi <ra...@gmail.com>.
On 4/13/07, Fargusson.Alan <Al...@ftb.ca.gov> wrote:
> I am putting my Resource inside the GlobalNamingResource.  Do I need anything in the Context node?
>

If you are using GlobalNamingResource you don't need the Context node
because it is global to all contexts and not just one context.

> I have been doing this two different ways.  My latest attempts I have used the management > console which generates the server.xml file.

Focus on one way :-) and get it to work before attempting alternatives.

>

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


TOMCAT 5.0.28 Start-up issue

Posted by Dwight Farris <df...@email.arizona.edu>.
Hello All,
When I start TOMCAT 5.0.28 on a MAC OS X server; I intermittently receive
the following errors:

web1:~/tomcat/bin dfarris$ ./startup.sh
Using CATALINA_BASE:   /Volumes/Data/home/dfarris/tomcat
Using CATALINA_HOME:   /Volumes/Data/home/dfarris/tomcat
Using CATALINA_TMPDIR: /Volumes/Data/home/dfarris/tomcat/temp
Using JAVA_HOME:       /Library/Java/Home

/Volumes/Data/home/dfarris/tomcat/bin/catalina.sh: line 295: 11435 Bus error
"$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH"
-Dcatalina.base="$CATALINA_BASE" -Dcatalina.home="$CATALINA_HOME"
-Djava.io.tmpdir="$CATALINA_TMPDIR" org.apache.catalina.startup.Bootstrap
"$@" start >>"$CATALINA_BASE"/logs/catalina.out 2>&1

/Volumes/Data/home/dfarris/tomcat/bin/catalina.sh: line 295: 11459 Illegal
instruction     "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH"
-Dcatalina.base="$CATALINA_BASE" -Dcatalina.home="$CATALINA_HOME"
-Djava.io.tmpdir="$CATALINA_TMPDIR" org.apache.catalina.startup.Bootstrap
"$@" start >>"$CATALINA_BASE"/logs/catalina.out 2>&1

Any assistance is greatly appreciated


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


RE: DB2 DataSource.

Posted by "Fargusson.Alan" <Al...@ftb.ca.gov>.
I am putting my Resource inside the GlobalNamingResource.  Do I need anything in the Context node?

I have been doing this two different ways.  My latest attempts I have used the management console which generates the server.xml file.

-----Original Message-----
From: Rashmi Rubdi [mailto:rashmi.sub@gmail.com]
Sent: Friday, April 13, 2007 10:27 AM
To: Tomcat Users List
Subject: Re: DB2 DataSource.


As Len Popp mentioned before, the syntax for Connection Pooling is
different for certain versions of Tomcat.

If you carefully follow the documentation of "JDBC DataSources" for
*your* version of Tomcat http://tomcat.apache.org/ , and do some
additional minor research on the pseudo-code presented in the  How-To
document, you should be able to connect with Connection Pooling.

One common mistake I've seen is people forget to nest the Context node
inside the Host node, or forget to associate an external Context file
to a particular Host in server.xml

If you think anything is misconfigured or too confusing, it helps to
start with a fresh install of the version of Tomcat you intend to use.

-Rashmi

On 4/13/07, Fargusson.Alan <Al...@ftb.ca.gov> wrote:
> Your right.  My ResourceParam syntax is different.  I didn't look closely at that.  My values are mostly the same.
>

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


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


Re: DB2 DataSource.

Posted by Rashmi Rubdi <ra...@gmail.com>.
As Len Popp mentioned before, the syntax for Connection Pooling is
different for certain versions of Tomcat.

If you carefully follow the documentation of "JDBC DataSources" for
*your* version of Tomcat http://tomcat.apache.org/ , and do some
additional minor research on the pseudo-code presented in the  How-To
document, you should be able to connect with Connection Pooling.

One common mistake I've seen is people forget to nest the Context node
inside the Host node, or forget to associate an external Context file
to a particular Host in server.xml

If you think anything is misconfigured or too confusing, it helps to
start with a fresh install of the version of Tomcat you intend to use.

-Rashmi

On 4/13/07, Fargusson.Alan <Al...@ftb.ca.gov> wrote:
> Your right.  My ResourceParam syntax is different.  I didn't look closely at that.  My values are mostly the same.
>

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


RE: DB2 DataSource.

Posted by "Fargusson.Alan" <Al...@ftb.ca.gov>.
Your right.  My ResourceParam syntax is different.  I didn't look closely at that.  My values are mostly the same.

-----Original Message-----
From: Len Popp [mailto:len.popp@gmail.com]
Sent: Friday, April 13, 2007 9:25 AM
To: Tomcat Users List
Subject: Re: DB2 DataSource.


It should *not* look the same, because the syntax of the <Resource>
element changed after 5.0. Look for <ResourceParam> in the 5.0
documentation.
-- 
Len

On 4/13/07, Fargusson.Alan <Al...@ftb.ca.gov> wrote:
> Thanks.  I am using 5.0.28, but what I have looks like what you have.  I will take a closer look to make sure I didn't miss something.
>
> -----Original Message-----
> From: Rashmi Rubdi [mailto:rashmi.sub@gmail.com]
> Sent: Thursday, April 12, 2007 5:59 PM
> To: Tomcat Users List
> Subject: Re: DB2 DataSource.
>
>
> Your Tomcat version is not known, so I'm assuming the latest version 6.0.10.
>
> Here's what should go in:
> ------------------------------------------------------
> ...../MyProject/WEB-INF/web.xml
> ------------------------------------------------------
> <?xml version="1.0"?>
> <web-app xmlns="http://java.sun.com/xml/ns/javaee"
>          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-app_2_5.xsd"
>          version="2.5">
>   <description>MySQL Test App</description>
>   <resource-ref>
>       <description>DB Connection</description>
>       <res-ref-name>jdbc/TestDB</res-ref-name>
>       <res-type>javax.sql.DataSource</res-type>
>       <res-auth>Container</res-auth>
>   </resource-ref>
> </web-app>
>
> -----------------------------------------------------------------------------------------
> According to the HOW-TO document I gave earlier the JAR for the JDBC
> driver must be placed in Tomcat's lib folder, so
> .......\apache-tomcat-6.0.10_bak_20070410\lib\
> -----------------------------------------------------------------------------------------
> mysql-connector-java-5.0.5-bin.jar
>
> -----------------------------------------------------------------------------------------
> Add the connection pooling configuration to your application's Context
> definition
> -----------------------------------------------------------------------------------------
>         <Context path="" docBase="C:/dev/projects/ConnectionPooling"
> reloadable="true" debug="true">
>                 <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
>                         maxActive="100" maxIdle="30" maxWait="10000"
>                         username="javauser" password="javadude"
> driverClassName="com.mysql.jdbc.Driver"
>                         url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true"/>
>         </Context>
>
>
> -----------------------------------------------------------------------------------------
> And finally, here's the sample working code:
> /WEB-INF/classes/com/connectionpooltest/ConnectionPoolTest.java
> ----------------------------------------------------------------------------------------
> package com.connectionpooltest;
>
> import java.sql.*;
> import javax.naming.*;
> import javax.sql.DataSource;
>
> public class ConnectionPoolTest {
>
>     public void testConnection() throws SQLException, NamingException{
>         Connection conn = null;
>         Statement stmt = null;
>         ResultSet rs = null;
>
>         try{
>             //conn = ... get connection from connection pool ...
>             Context initContext = new InitialContext();
>             Context envContext  = (Context)initContext.lookup("java:/comp/env");
>             DataSource ds = (DataSource)envContext.lookup("jdbc/TestDB");
>             conn = ds.getConnection();
>
>             //stmt = conn.createStatement("select ...");
>             stmt = conn.createStatement();
>
>             //rs = stmt.executeQuery();
>             rs = stmt.executeQuery("SELECT 'Java Connection Pooling Test' as
> a FROM dual");
>
>             //... iterate through the result set ...
>                 while (rs.next()) {
>                     String s = rs.getString("a");
>                     System.out.println(" s is : " + s);
>                 }
>
>             rs.close();
>             rs = null;
>             stmt.close();
>             stmt = null;
>             conn.close(); // Return to connection pool
>             conn = null;  // Make sure we don't close it twice
>
>         }catch(SQLException e){
>                 e.printStackTrace();
>         }finally{
>             // Always make sure result sets and statements are closed,
>             // and the connection is returned to the pool
>             if (rs != null) {
>               try { rs.close(); } catch (SQLException e) { e.printStackTrace(); }
>               rs = null;
>             }
>             if (stmt != null) {
>               try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); }
>               stmt = null;
>             }
>             if (conn != null) {
>               try { conn.close(); } catch (SQLException e) { e.printStackTrace(); }
>               conn = null;
>             }
>         }
>     }
>
> }
>
> Since Connection Pooling is handled by the Container, the above code
> must be called from within the context of the Container --- so it must
> be called from either a Servlet or a JSP page --- it cannot be called
> from the command line alone using a main method.
>
> -Rashmi
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

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


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


Re: DB2 DataSource.

Posted by Len Popp <le...@gmail.com>.
It should *not* look the same, because the syntax of the <Resource>
element changed after 5.0. Look for <ResourceParam> in the 5.0
documentation.
-- 
Len

On 4/13/07, Fargusson.Alan <Al...@ftb.ca.gov> wrote:
> Thanks.  I am using 5.0.28, but what I have looks like what you have.  I will take a closer look to make sure I didn't miss something.
>
> -----Original Message-----
> From: Rashmi Rubdi [mailto:rashmi.sub@gmail.com]
> Sent: Thursday, April 12, 2007 5:59 PM
> To: Tomcat Users List
> Subject: Re: DB2 DataSource.
>
>
> Your Tomcat version is not known, so I'm assuming the latest version 6.0.10.
>
> Here's what should go in:
> ------------------------------------------------------
> ...../MyProject/WEB-INF/web.xml
> ------------------------------------------------------
> <?xml version="1.0"?>
> <web-app xmlns="http://java.sun.com/xml/ns/javaee"
>          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-app_2_5.xsd"
>          version="2.5">
>   <description>MySQL Test App</description>
>   <resource-ref>
>       <description>DB Connection</description>
>       <res-ref-name>jdbc/TestDB</res-ref-name>
>       <res-type>javax.sql.DataSource</res-type>
>       <res-auth>Container</res-auth>
>   </resource-ref>
> </web-app>
>
> -----------------------------------------------------------------------------------------
> According to the HOW-TO document I gave earlier the JAR for the JDBC
> driver must be placed in Tomcat's lib folder, so
> .......\apache-tomcat-6.0.10_bak_20070410\lib\
> -----------------------------------------------------------------------------------------
> mysql-connector-java-5.0.5-bin.jar
>
> -----------------------------------------------------------------------------------------
> Add the connection pooling configuration to your application's Context
> definition
> -----------------------------------------------------------------------------------------
>         <Context path="" docBase="C:/dev/projects/ConnectionPooling"
> reloadable="true" debug="true">
>                 <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
>                         maxActive="100" maxIdle="30" maxWait="10000"
>                         username="javauser" password="javadude"
> driverClassName="com.mysql.jdbc.Driver"
>                         url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true"/>
>         </Context>
>
>
> -----------------------------------------------------------------------------------------
> And finally, here's the sample working code:
> /WEB-INF/classes/com/connectionpooltest/ConnectionPoolTest.java
> ----------------------------------------------------------------------------------------
> package com.connectionpooltest;
>
> import java.sql.*;
> import javax.naming.*;
> import javax.sql.DataSource;
>
> public class ConnectionPoolTest {
>
>     public void testConnection() throws SQLException, NamingException{
>         Connection conn = null;
>         Statement stmt = null;
>         ResultSet rs = null;
>
>         try{
>             //conn = ... get connection from connection pool ...
>             Context initContext = new InitialContext();
>             Context envContext  = (Context)initContext.lookup("java:/comp/env");
>             DataSource ds = (DataSource)envContext.lookup("jdbc/TestDB");
>             conn = ds.getConnection();
>
>             //stmt = conn.createStatement("select ...");
>             stmt = conn.createStatement();
>
>             //rs = stmt.executeQuery();
>             rs = stmt.executeQuery("SELECT 'Java Connection Pooling Test' as
> a FROM dual");
>
>             //... iterate through the result set ...
>                 while (rs.next()) {
>                     String s = rs.getString("a");
>                     System.out.println(" s is : " + s);
>                 }
>
>             rs.close();
>             rs = null;
>             stmt.close();
>             stmt = null;
>             conn.close(); // Return to connection pool
>             conn = null;  // Make sure we don't close it twice
>
>         }catch(SQLException e){
>                 e.printStackTrace();
>         }finally{
>             // Always make sure result sets and statements are closed,
>             // and the connection is returned to the pool
>             if (rs != null) {
>               try { rs.close(); } catch (SQLException e) { e.printStackTrace(); }
>               rs = null;
>             }
>             if (stmt != null) {
>               try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); }
>               stmt = null;
>             }
>             if (conn != null) {
>               try { conn.close(); } catch (SQLException e) { e.printStackTrace(); }
>               conn = null;
>             }
>         }
>     }
>
> }
>
> Since Connection Pooling is handled by the Container, the above code
> must be called from within the context of the Container --- so it must
> be called from either a Servlet or a JSP page --- it cannot be called
> from the command line alone using a main method.
>
> -Rashmi
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

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


RE: DB2 DataSource.

Posted by "Fargusson.Alan" <Al...@ftb.ca.gov>.
Thanks.  I am using 5.0.28, but what I have looks like what you have.  I will take a closer look to make sure I didn't miss something.

-----Original Message-----
From: Rashmi Rubdi [mailto:rashmi.sub@gmail.com]
Sent: Thursday, April 12, 2007 5:59 PM
To: Tomcat Users List
Subject: Re: DB2 DataSource.


Your Tomcat version is not known, so I'm assuming the latest version 6.0.10.

Here's what should go in:
------------------------------------------------------
...../MyProject/WEB-INF/web.xml
------------------------------------------------------
<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-app_2_5.xsd"
         version="2.5">
  <description>MySQL Test App</description>
  <resource-ref>
      <description>DB Connection</description>
      <res-ref-name>jdbc/TestDB</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>
</web-app>

-----------------------------------------------------------------------------------------
According to the HOW-TO document I gave earlier the JAR for the JDBC
driver must be placed in Tomcat's lib folder, so
.......\apache-tomcat-6.0.10_bak_20070410\lib\
-----------------------------------------------------------------------------------------
mysql-connector-java-5.0.5-bin.jar

-----------------------------------------------------------------------------------------
Add the connection pooling configuration to your application's Context
definition
-----------------------------------------------------------------------------------------
      	<Context path="" docBase="C:/dev/projects/ConnectionPooling"
reloadable="true" debug="true">
		<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
			maxActive="100" maxIdle="30" maxWait="10000"
			username="javauser" password="javadude"
driverClassName="com.mysql.jdbc.Driver"
			url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true"/>	
	</Context>


-----------------------------------------------------------------------------------------
And finally, here's the sample working code:
/WEB-INF/classes/com/connectionpooltest/ConnectionPoolTest.java
----------------------------------------------------------------------------------------
package com.connectionpooltest;

import java.sql.*;
import javax.naming.*;
import javax.sql.DataSource;

public class ConnectionPoolTest {

    public void testConnection() throws SQLException, NamingException{
	Connection conn = null;
	Statement stmt = null;
	ResultSet rs = null;
	
	try{
	    //conn = ... get connection from connection pool ...
	    Context initContext = new InitialContext();
	    Context envContext  = (Context)initContext.lookup("java:/comp/env");
	    DataSource ds = (DataSource)envContext.lookup("jdbc/TestDB");
	    conn = ds.getConnection();
	
	    //stmt = conn.createStatement("select ...");
	    stmt = conn.createStatement();
	
	    //rs = stmt.executeQuery();
	    rs = stmt.executeQuery("SELECT 'Java Connection Pooling Test' as
a FROM dual");
	
	    //... iterate through the result set ...
		while (rs.next()) {
		    String s = rs.getString("a");
		    System.out.println(" s is : " + s);
		}
	
	    rs.close();
	    rs = null;
	    stmt.close();
	    stmt = null;
	    conn.close(); // Return to connection pool
	    conn = null;  // Make sure we don't close it twice
	
    	}catch(SQLException e){
		e.printStackTrace();	
	}finally{
	    // Always make sure result sets and statements are closed,
	    // and the connection is returned to the pool
	    if (rs != null) {
	      try { rs.close(); } catch (SQLException e) { e.printStackTrace(); }
	      rs = null;
	    }
	    if (stmt != null) {
	      try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); }
	      stmt = null;
	    }
	    if (conn != null) {
	      try { conn.close(); } catch (SQLException e) { e.printStackTrace(); }
	      conn = null;
	    }		
	}
    }

}

Since Connection Pooling is handled by the Container, the above code
must be called from within the context of the Container --- so it must
be called from either a Servlet or a JSP page --- it cannot be called
from the command line alone using a main method.

-Rashmi

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


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


Re: DB2 DataSource.

Posted by Rashmi Rubdi <ra...@gmail.com>.
Your Tomcat version is not known, so I'm assuming the latest version 6.0.10.

Here's what should go in:
------------------------------------------------------
...../MyProject/WEB-INF/web.xml
------------------------------------------------------
<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-app_2_5.xsd"
         version="2.5">
  <description>MySQL Test App</description>
  <resource-ref>
      <description>DB Connection</description>
      <res-ref-name>jdbc/TestDB</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>
</web-app>

-----------------------------------------------------------------------------------------
According to the HOW-TO document I gave earlier the JAR for the JDBC
driver must be placed in Tomcat's lib folder, so
.......\apache-tomcat-6.0.10_bak_20070410\lib\
-----------------------------------------------------------------------------------------
mysql-connector-java-5.0.5-bin.jar

-----------------------------------------------------------------------------------------
Add the connection pooling configuration to your application's Context
definition
-----------------------------------------------------------------------------------------
      	<Context path="" docBase="C:/dev/projects/ConnectionPooling"
reloadable="true" debug="true">
		<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
			maxActive="100" maxIdle="30" maxWait="10000"
			username="javauser" password="javadude"
driverClassName="com.mysql.jdbc.Driver"
			url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true"/>	
	</Context>


-----------------------------------------------------------------------------------------
And finally, here's the sample working code:
/WEB-INF/classes/com/connectionpooltest/ConnectionPoolTest.java
----------------------------------------------------------------------------------------
package com.connectionpooltest;

import java.sql.*;
import javax.naming.*;
import javax.sql.DataSource;

public class ConnectionPoolTest {

    public void testConnection() throws SQLException, NamingException{
	Connection conn = null;
	Statement stmt = null;
	ResultSet rs = null;
	
	try{
	    //conn = ... get connection from connection pool ...
	    Context initContext = new InitialContext();
	    Context envContext  = (Context)initContext.lookup("java:/comp/env");
	    DataSource ds = (DataSource)envContext.lookup("jdbc/TestDB");
	    conn = ds.getConnection();
	
	    //stmt = conn.createStatement("select ...");
	    stmt = conn.createStatement();
	
	    //rs = stmt.executeQuery();
	    rs = stmt.executeQuery("SELECT 'Java Connection Pooling Test' as
a FROM dual");
	
	    //... iterate through the result set ...
		while (rs.next()) {
		    String s = rs.getString("a");
		    System.out.println(" s is : " + s);
		}
	
	    rs.close();
	    rs = null;
	    stmt.close();
	    stmt = null;
	    conn.close(); // Return to connection pool
	    conn = null;  // Make sure we don't close it twice
	
    	}catch(SQLException e){
		e.printStackTrace();	
	}finally{
	    // Always make sure result sets and statements are closed,
	    // and the connection is returned to the pool
	    if (rs != null) {
	      try { rs.close(); } catch (SQLException e) { e.printStackTrace(); }
	      rs = null;
	    }
	    if (stmt != null) {
	      try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); }
	      stmt = null;
	    }
	    if (conn != null) {
	      try { conn.close(); } catch (SQLException e) { e.printStackTrace(); }
	      conn = null;
	    }		
	}
    }

}

Since Connection Pooling is handled by the Container, the above code
must be called from within the context of the Container --- so it must
be called from either a Servlet or a JSP page --- it cannot be called
from the command line alone using a main method.

-Rashmi

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


RE: DB2 DataSource.

Posted by "Fargusson.Alan" <Al...@ftb.ca.gov>.
It might be helpful to look at your code.  I suspect that getting DB2 to work involves more then just replacing the MySql driver with a DB2 equivalent.

I have tried using the examples to get this to work.

-----Original Message-----
From: Rashmi Rubdi [mailto:rashmi.sub@gmail.com]
Sent: Thursday, April 12, 2007 4:56 PM
To: Tomcat Users List
Subject: Re: DB2 DataSource.


I tried the example shown at the bottom of the page here:
http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html
with MySQL and I got it to work, but I don't have DB2.

If you want the code with MySQL I can post it.

-Rashmi

On 4/12/07, Fargusson.Alan <Al...@ftb.ca.gov> wrote:
> I am hoping that someone has a working example that they actually tested.

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


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


Re: DB2 DataSource.

Posted by Rashmi Rubdi <ra...@gmail.com>.
I tried the example shown at the bottom of the page here:
http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html
with MySQL and I got it to work, but I don't have DB2.

If you want the code with MySQL I can post it.

-Rashmi

On 4/12/07, Fargusson.Alan <Al...@ftb.ca.gov> wrote:
> I am hoping that someone has a working example that they actually tested.

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


RE: DB2 DataSource.

Posted by "Fargusson.Alan" <Al...@ftb.ca.gov>.
I think I have all the jar files in the right place.  In fact I can access DB2 when I use DriverManager.

-----Original Message-----
From: Foo Shyn [mailto:fooshyn@optegra.com.my]
Sent: Thursday, April 12, 2007 11:14 PM
To: Tomcat Users List
Cc: Martin Gainty
Subject: Re: DB2 DataSource.


Hi,

I'd been using connection pooling setting in Tomcat for MySQL, MSSQL and 
Derby(or Cloudscape) so i guess DB2 could be setup just as same.

Make sure your driver jar file includes the Driver which is packaged as you 
had declared in the XML. And place it in the Tomcat common lib folder (In 
Tomcat 4.1's case, Tomcat 4.1\common\lib).

Thanx.
Regards,
FooShyn
----- Original Message ----- 
From: "Pulkit Singhal" <pu...@gmail.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Cc: "Martin Gainty" <mg...@hotmail.com>
Sent: Friday, April 13, 2007 1:05 PM
Subject: Re: DB2 DataSource.


> The following is copy/pasted from
> http://jtds.sourceforge.net/faq.html#noSuitableDriver
>
> Why do I get a java.sql.SQLException: "No suitable driver" when trying to
> get a connection?
>
> The "No suitable driver" exception is thrown by the DriverManager when 
> none
> of the registered Driver implementations recognizes the supplied URL. This
> means that you either did not register jTDS with the DriverManager first 
> (by
> calling Class.forName("net.sourceforge.jtds.jdbc.Driver")) or you mistyped
> the URL (e.g. "jbdc:jtds:..." instead of "jdbc:jtds:...").
>
> A common mistake is to append a semicolon (";") to the end of the URL 
> (e.g.
> "jdbc:jtds:sqlserver://server/db;TDS=7.0;" is wrong!).
>
> For more information about URL format and the properties that may be 
> passed
> to jTDS have a look at the jTDS URL
> format<http://jtds.sourceforge.net/faq.html#urlFormat>
> .
>
>
> On 4/12/07, Fargusson.Alan <Al...@ftb.ca.gov> wrote:
>>
>> Thanks.  Unfortunately I did try this example before.  It doesn't work. 
>> I
>> get an exception, and along with the stack dump I display I get "Caused 
>> by:
>> java.sql.SQLException: No suitable driver".
>>
>> I am hoping that someone has a working example that they actually tested.
>>
>> -----Original Message-----
>> From: Martin Gainty [mailto:mgainty@hotmail.com]
>> Sent: Thursday, April 12, 2007 3:19 PM
>> To: Tomcat Users List
>> Subject: Re: DB2 DataSource.
>>
>>
>> Alan-
>>
>> http://www.itjungle.com/fhg/fhg051204-story01.html
>>
>> Viel Gluck/Buena Suerte
>>
>> Martin--
>> This email message and any files transmitted with it contain confidential
>> information intended only for the person(s) to whom this email message is
>> addressed.  If you have received this email message in error, please
>> notify
>> the sender immediately by telephone or email and destroy the original
>> message without making a copy.  Thank you.
>>
>> ----- Original Message -----
>> From: "Fargusson.Alan" <Al...@ftb.ca.gov>
>> To: <us...@tomcat.apache.org>
>> Sent: Thursday, April 12, 2007 6:01 PM
>> Subject: DB2 DataSource.
>>
>>
>> Can someone point me to documentation on setting up a DataSource to DB2?
>>
>> I tried to use the examples for Oracle and MySql, but I have not been 
>> able
>> to get it to work.
>>
>> I am able to access DB2 using the DriverManager.
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>


--------------------------------------------------------------------------------


No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 269.3.0/758 - Release Date: 4/12/2007 
11:52 AM



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


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


Re: DB2 DataSource.

Posted by Foo Shyn <fo...@optegra.com.my>.
Hi,

I'd been using connection pooling setting in Tomcat for MySQL, MSSQL and 
Derby(or Cloudscape) so i guess DB2 could be setup just as same.

Make sure your driver jar file includes the Driver which is packaged as you 
had declared in the XML. And place it in the Tomcat common lib folder (In 
Tomcat 4.1's case, Tomcat 4.1\common\lib).

Thanx.
Regards,
FooShyn
----- Original Message ----- 
From: "Pulkit Singhal" <pu...@gmail.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Cc: "Martin Gainty" <mg...@hotmail.com>
Sent: Friday, April 13, 2007 1:05 PM
Subject: Re: DB2 DataSource.


> The following is copy/pasted from
> http://jtds.sourceforge.net/faq.html#noSuitableDriver
>
> Why do I get a java.sql.SQLException: "No suitable driver" when trying to
> get a connection?
>
> The "No suitable driver" exception is thrown by the DriverManager when 
> none
> of the registered Driver implementations recognizes the supplied URL. This
> means that you either did not register jTDS with the DriverManager first 
> (by
> calling Class.forName("net.sourceforge.jtds.jdbc.Driver")) or you mistyped
> the URL (e.g. "jbdc:jtds:..." instead of "jdbc:jtds:...").
>
> A common mistake is to append a semicolon (";") to the end of the URL 
> (e.g.
> "jdbc:jtds:sqlserver://server/db;TDS=7.0;" is wrong!).
>
> For more information about URL format and the properties that may be 
> passed
> to jTDS have a look at the jTDS URL
> format<http://jtds.sourceforge.net/faq.html#urlFormat>
> .
>
>
> On 4/12/07, Fargusson.Alan <Al...@ftb.ca.gov> wrote:
>>
>> Thanks.  Unfortunately I did try this example before.  It doesn't work. 
>> I
>> get an exception, and along with the stack dump I display I get "Caused 
>> by:
>> java.sql.SQLException: No suitable driver".
>>
>> I am hoping that someone has a working example that they actually tested.
>>
>> -----Original Message-----
>> From: Martin Gainty [mailto:mgainty@hotmail.com]
>> Sent: Thursday, April 12, 2007 3:19 PM
>> To: Tomcat Users List
>> Subject: Re: DB2 DataSource.
>>
>>
>> Alan-
>>
>> http://www.itjungle.com/fhg/fhg051204-story01.html
>>
>> Viel Gluck/Buena Suerte
>>
>> Martin--
>> This email message and any files transmitted with it contain confidential
>> information intended only for the person(s) to whom this email message is
>> addressed.  If you have received this email message in error, please
>> notify
>> the sender immediately by telephone or email and destroy the original
>> message without making a copy.  Thank you.
>>
>> ----- Original Message -----
>> From: "Fargusson.Alan" <Al...@ftb.ca.gov>
>> To: <us...@tomcat.apache.org>
>> Sent: Thursday, April 12, 2007 6:01 PM
>> Subject: DB2 DataSource.
>>
>>
>> Can someone point me to documentation on setting up a DataSource to DB2?
>>
>> I tried to use the examples for Oracle and MySql, but I have not been 
>> able
>> to get it to work.
>>
>> I am able to access DB2 using the DriverManager.
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>


--------------------------------------------------------------------------------


No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 269.3.0/758 - Release Date: 4/12/2007 
11:52 AM



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


RE: DB2 DataSource.

Posted by "Fargusson.Alan" <Al...@ftb.ca.gov>.
Actually my program works when I use DriverManager.  It only failes when I use a DataSource.

-----Original Message-----
From: Pulkit Singhal [mailto:pulkitsinghal@gmail.com]
Sent: Thursday, April 12, 2007 10:06 PM
To: Tomcat Users List
Cc: Martin Gainty
Subject: Re: DB2 DataSource.


The following is copy/pasted from
http://jtds.sourceforge.net/faq.html#noSuitableDriver

Why do I get a java.sql.SQLException: "No suitable driver" when trying to
get a connection?

The "No suitable driver" exception is thrown by the DriverManager when none
of the registered Driver implementations recognizes the supplied URL. This
means that you either did not register jTDS with the DriverManager first (by
calling Class.forName("net.sourceforge.jtds.jdbc.Driver")) or you mistyped
the URL (e.g. "jbdc:jtds:..." instead of "jdbc:jtds:...").

A common mistake is to append a semicolon (";") to the end of the URL (e.g.
"jdbc:jtds:sqlserver://server/db;TDS=7.0;" is wrong!).

For more information about URL format and the properties that may be passed
to jTDS have a look at the jTDS URL
format<http://jtds.sourceforge.net/faq.html#urlFormat>
.


On 4/12/07, Fargusson.Alan <Al...@ftb.ca.gov> wrote:
>
> Thanks.  Unfortunately I did try this example before.  It doesn't work.  I
> get an exception, and along with the stack dump I display I get "Caused by:
> java.sql.SQLException: No suitable driver".
>
> I am hoping that someone has a working example that they actually tested.
>
> -----Original Message-----
> From: Martin Gainty [mailto:mgainty@hotmail.com]
> Sent: Thursday, April 12, 2007 3:19 PM
> To: Tomcat Users List
> Subject: Re: DB2 DataSource.
>
>
> Alan-
>
> http://www.itjungle.com/fhg/fhg051204-story01.html
>
> Viel Gluck/Buena Suerte
>
> Martin--
> This email message and any files transmitted with it contain confidential
> information intended only for the person(s) to whom this email message is
> addressed.  If you have received this email message in error, please
> notify
> the sender immediately by telephone or email and destroy the original
> message without making a copy.  Thank you.
>
> ----- Original Message -----
> From: "Fargusson.Alan" <Al...@ftb.ca.gov>
> To: <us...@tomcat.apache.org>
> Sent: Thursday, April 12, 2007 6:01 PM
> Subject: DB2 DataSource.
>
>
> Can someone point me to documentation on setting up a DataSource to DB2?
>
> I tried to use the examples for Oracle and MySql, but I have not been able
> to get it to work.
>
> I am able to access DB2 using the DriverManager.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

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


Re: DB2 DataSource.

Posted by Pulkit Singhal <pu...@gmail.com>.
The following is copy/pasted from
http://jtds.sourceforge.net/faq.html#noSuitableDriver

Why do I get a java.sql.SQLException: "No suitable driver" when trying to
get a connection?

The "No suitable driver" exception is thrown by the DriverManager when none
of the registered Driver implementations recognizes the supplied URL. This
means that you either did not register jTDS with the DriverManager first (by
calling Class.forName("net.sourceforge.jtds.jdbc.Driver")) or you mistyped
the URL (e.g. "jbdc:jtds:..." instead of "jdbc:jtds:...").

A common mistake is to append a semicolon (";") to the end of the URL (e.g.
"jdbc:jtds:sqlserver://server/db;TDS=7.0;" is wrong!).

For more information about URL format and the properties that may be passed
to jTDS have a look at the jTDS URL
format<http://jtds.sourceforge.net/faq.html#urlFormat>
.


On 4/12/07, Fargusson.Alan <Al...@ftb.ca.gov> wrote:
>
> Thanks.  Unfortunately I did try this example before.  It doesn't work.  I
> get an exception, and along with the stack dump I display I get "Caused by:
> java.sql.SQLException: No suitable driver".
>
> I am hoping that someone has a working example that they actually tested.
>
> -----Original Message-----
> From: Martin Gainty [mailto:mgainty@hotmail.com]
> Sent: Thursday, April 12, 2007 3:19 PM
> To: Tomcat Users List
> Subject: Re: DB2 DataSource.
>
>
> Alan-
>
> http://www.itjungle.com/fhg/fhg051204-story01.html
>
> Viel Gluck/Buena Suerte
>
> Martin--
> This email message and any files transmitted with it contain confidential
> information intended only for the person(s) to whom this email message is
> addressed.  If you have received this email message in error, please
> notify
> the sender immediately by telephone or email and destroy the original
> message without making a copy.  Thank you.
>
> ----- Original Message -----
> From: "Fargusson.Alan" <Al...@ftb.ca.gov>
> To: <us...@tomcat.apache.org>
> Sent: Thursday, April 12, 2007 6:01 PM
> Subject: DB2 DataSource.
>
>
> Can someone point me to documentation on setting up a DataSource to DB2?
>
> I tried to use the examples for Oracle and MySql, but I have not been able
> to get it to work.
>
> I am able to access DB2 using the DriverManager.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

RE: DB2 DataSource.

Posted by "Fargusson.Alan" <Al...@ftb.ca.gov>.
Thanks.  Unfortunately I did try this example before.  It doesn't work.  I get an exception, and along with the stack dump I display I get "Caused by: java.sql.SQLException: No suitable driver".

I am hoping that someone has a working example that they actually tested.

-----Original Message-----
From: Martin Gainty [mailto:mgainty@hotmail.com]
Sent: Thursday, April 12, 2007 3:19 PM
To: Tomcat Users List
Subject: Re: DB2 DataSource.


Alan-

http://www.itjungle.com/fhg/fhg051204-story01.html

Viel Gluck/Buena Suerte

Martin--
This email message and any files transmitted with it contain confidential
information intended only for the person(s) to whom this email message is
addressed.  If you have received this email message in error, please notify
the sender immediately by telephone or email and destroy the original
message without making a copy.  Thank you.

----- Original Message ----- 
From: "Fargusson.Alan" <Al...@ftb.ca.gov>
To: <us...@tomcat.apache.org>
Sent: Thursday, April 12, 2007 6:01 PM
Subject: DB2 DataSource.


Can someone point me to documentation on setting up a DataSource to DB2?

I tried to use the examples for Oracle and MySql, but I have not been able 
to get it to work.

I am able to access DB2 using the DriverManager.

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



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


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


Re: DB2 DataSource.

Posted by Martin Gainty <mg...@hotmail.com>.
Alan-

http://www.itjungle.com/fhg/fhg051204-story01.html

Viel Gluck/Buena Suerte

Martin--
This email message and any files transmitted with it contain confidential
information intended only for the person(s) to whom this email message is
addressed.  If you have received this email message in error, please notify
the sender immediately by telephone or email and destroy the original
message without making a copy.  Thank you.

----- Original Message ----- 
From: "Fargusson.Alan" <Al...@ftb.ca.gov>
To: <us...@tomcat.apache.org>
Sent: Thursday, April 12, 2007 6:01 PM
Subject: DB2 DataSource.


Can someone point me to documentation on setting up a DataSource to DB2?

I tried to use the examples for Oracle and MySql, but I have not been able 
to get it to work.

I am able to access DB2 using the DriverManager.

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



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