tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Wulff <ewu...@gmail.com>
Subject Re: connection pooling
Date Thu, 07 Oct 2004 20:34:02 GMT
Hi Phillip,

On Thu, 7 Oct 2004 09:29:09 -0400, you wrote:
> Detail, detail, detail.
> 
> 1. your context.xml
> 2. your web.xml
> 3. how do you obtain connection from pool, java code pls.
> 4. can you connect using pool
> 5. commons-pool version
> 
> Etc. etc.
> 
> You need to provide details otherwise we can't help.

This was all included in my original post.  Ok, actually my 2nd post
because I accidentally hit send prior to completing my post via the
scroll pad on my laptop.  Still, thx for checking on this and the info
you looking for is copied again here...

System:
Tomcat 5 on Fedora Core 2 connecting to a db on an Informix Dynamic
Server 9.4 on Windows Server

-I am able to connect to my db via typical JDBC
DriverManager.getConnection().  This leads me to believe that my
informix jdbc driver is in the correct place...
CATALINA_HOME/common/lib
-I have a Context set up in my server.xml per examples in a text
tutorial I'm referencing

Below listed...
-errors
-web.xml
-server.xml <Context> (minus connection actual values)
-.java

exception/errors:
-Exception: org.apache.commons.dbcp.SQLNestedException: Cannot create
JDBC driver of class '' for connect URL 'null'
SQL state: null
Error code: 0

-stack trace reveals this, but I can't see why since I have the driver
in the correct directory...
java.sql.SQLException: No suitable driver at
java.sql.DriverManager.getDriver(DriverManager.java:243) at
org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:773)

web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
   PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
   "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
       <servlet>
               <servlet-name>Test Connection Pooling</servlet-name>
               <servlet-class>TestConnectionPooling</servlet-class>
       </servlet>

       <servlet-mapping>
               <servlet-name>Test Connection Pooling</servlet-name>
               <url-pattern>/testConnectionPooling</url-pattern>
       </servlet-mapping>

       <resource-ref>
         <res-ref-name>jdbc/test_connect</res-ref-name>
         <res-type>javax.sql.DataSource</res-type>
         <res-auth>Container</res-auth>
       </resource-ref>
</web-app>

server.xml <Context>:
 <Context path="/testConnectionPooling"
docBase="testConnectionPooling" debug="0" reloadable="true">
   <ResourceParams name="jdbc/test_connect">
     <parameter>
       <name>username</name>
       <value>informix</value>
     </parameter>
     <parameter>
       <name>password</name>
       <value>informix</value>
     </parameter>
     <parameter>
       <name>driverClassName</name>
       <value>com.informix.jdbc.IfxDriver</value>
     </parameter>
     <parameter>
       <name>url</name>
<value>jdbc:informix-sqli://url:port/dbName:INFORMIXSERVER=serverName</value>
     </parameter>
   </ResourceParams>
 </Context>

.java:
import java.io.*;
import java.sql.*;
// -Must import javax.naming use JNDI which is required to implement data
//   resource references and hence connection pooling.
import javax.naming.*;
import javax.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

public class TestConnectionPooling extends HttpServlet {
       private DataSource dataSource;

       public void init(ServletConfig config) throws ServletException {
               try {
                       Context init = new InitialContext();
                       // don't know what the 'java:comp/env' refers to
                       Context ctx = (Context) init.lookup("java:comp/env");
                       // I know "jdbc/conversion must match the
web.xml res-ref-name of
the web.xml but don't know what the path really refers to
                       dataSource = (DataSource)
ctx.lookup("jdbc/test_connect");
               } catch (NamingException ex) {
                       throw new ServletException("Cannot retrieve
java:comp/env/jdbc/test_connect",ex);
               }
       }

       public void doGet(HttpServletRequest request,
HttpServletResponse response)
       throws ServletException, IOException {
               response.setContentType("text/html");
               PrintWriter out = response.getWriter();
               Connection connection = null;
               out.println ("<HTML><HEAD><TITLE>Test Connection
Pooling</TITLE></HEAD><BODY>");
               out.println("<H1>Customer Name Query</H1>");

               try {
                       synchronized(dataSource) {
                           connection = dataSource.getConnection();
                       }
                       out.println("<br>");
                       out.println("<strong>Loaded informix driver
successfully via
server.xml.</strong>" +
                                               "Now attempting db connection.");
                       out.println("<br>");
                       PreparedStatement pstmt =
connection.prepareStatement("SELECT blah
FROM blah blah");
                       ResultSet results = pstmt.executeQuery();
                       if (!results.next()) {
                               throw new SQLException("No data
returned for some reason");
                       }
                       out.println("<br>");
                       while(results.next()) {
                               out.println("<tr><td>" +
results.getString("blah") + "</td></tr>");
                       }
       } catch (Exception ex) {
                       out.println("<br>");
                       out.println("Exception: " + ex);
                       if(ex instanceof SQLException) {
                               SQLException sqlex = (SQLException) ex;
                               out.println("<br>");
                               out.println("SQL state:
"+sqlex.getSQLState()+"<BR>");
                               out.println("<br>");
                               out.println("Error code:
"+sqlex.getErrorCode()+"<BR>");
                               out.println("<br><br>");
                               sqlex.printStackTrace(out);
                               out.println("<br><br>");
                       }
       }
       finally {
           try { connection.close(); } catch (Exception ex) {}
       }
               out.println ("</BODY></HTML>");
   }
}

  ReplyForward
		
		
jthompson@honda.co.nz 	
java code: Context ctx = (Context) init.lookup("xxxxxx"); server.xml: <Resour...
	 	 Oct 6 (22 hours ago)
		
jthompson@honda.co.nz 	
Please ignore my last post - it's wrong. (Answered before verifying).
	 	 Oct 6 (22 hours ago)
		
jthompson@honda.co.nz 	
Is that litterally what you have in your server.xml?
	 	 Oct 6 (22 hours ago)
		
Eric Wulff 	
No, literally I have the actual values. The same connection string I use to s...
	 	 Oct 6 (22 hours ago)
		
jthompson@honda.co.nz 	
Is there a xxxxx.xml file in (TOMCAT_HOME)/conf/Catalina/localhost, where xxx...
	 	 Oct 6 (22 hours ago)
		
Eric Wulff 	
Context name? I assume your referring to the ResourceParams name attribute, j...
	 	 Oct 6 (19 hours ago)
		
Phillip Qin 	
<phillip.qin@shareowner.com> to Tomcat
	 More options	 6:29am (7 hours ago)
Detail, detail, detail.

1. your context.xml
2. your web.xml
3. how do you obtain connection from pool, java code pls.
4. can you connect using pool
5. commons-pool version

Etc. etc.

You need to provide details otherwise we can't help.
- Show quoted text -

-----Original Message-----
From: Eric Wulff [mailto:ewulff@gmail.com]
Sent: October 6, 2004 5:09 PM
To: tomcat-user@jakarta.apache.org
Subject: connection pooling

Hi all, I have gone over some of the tomcat docs and googled errors but
there is SO much information covering JNDI and Datasources... and I'm hoping
I don't have to be a JNDI/Datasource and XML guru just to set up db
connections via connection pool.

My situation is this...

System:
Tomcat 5 on Fedora Core 2 connecting to a db on an Informix Dynamic Server
9.4 on Windows Server

-I am able to connect to my db via typical JDBC
DriverManager.getConnection(). -This leads me to believe that my jdbc driver
is in the correct place ...CATALINA

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

!DSPAM:41645f0c199801939649086!


	
  ReplyForwardInvite Phillip to Gmail
Send  Save Draft  Discard      Check spelling
To:	
Cc:	
Bcc:	
	
Add Cc | Add Bcc | Edit Subject | Attach a file	
Subject:	
	
Attach a file
	
Send  Save Draft  Discard      Check spelling
	
		
		
Atishay Kumar 	
<atishay.kumar@gmail.com> to Tomcat, me
	 More options	 6:47am (6 hours ago)
On Wed, 6 Oct 2004 14:37:58 -0700, Eric Wulff <ewulff@gmail.com> wrote:
> I have gone over some of the tomcat docs and googled errors
> but there is SO much information covering JNDI, connection pooling,
> and Datasources.  Can someone review the info below and consult or
> point me in the right direction?  Although I feel I'm missing
> something obvious, I can't find out what's wrong with my set-up.
>
> thx
> Eric
>
> System:
> Tomcat 5 on Fedora Core 2 connecting to a db on an Informix Dynamic
> Server 9.4 on Windows Server
>
> -I am able to connect to my db via typical JDBC
> DriverManager.getConnection().  This leads me to believe that my
> informix jdbc driver is in the correct place...
> CATALINA_HOME/common/lib
> -I have a Context set up in my server.xml per examples in a text
> tutorial I'm referencing
>
> Below listed...
> -errors
> -web.xml
> -server.xml <Context> (minus connection actual values)
> -.java
>
> exception/errors:
> -Exception: org.apache.commons.dbcp.SQLNestedException: Cannot create
> JDBC driver of class '' for connect URL 'null'
> SQL state: null
> Error code: 0
>
> -stack trace reveals this, but I can't see why since I have the driver
> in the correct directory...
> java.sql.SQLException: No suitable driver at
> java.sql.DriverManager.getDriver(DriverManager.java:243) at
> org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:773)
>
> web.xml:
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <!DOCTYPE web-app
>     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
>     "http://java.sun.com/dtd/web-app_2_3.dtd">
> <web-app>
>         <servlet>
>                 <servlet-name>Test Connection Pooling</servlet-name>
>                 <servlet-class>TestConnectionPooling</servlet-class>
>         </servlet>
>
>         <servlet-mapping>
>                 <servlet-name>Test Connection Pooling</servlet-name>
>                 <url-pattern>/testConnectionPooling</url-pattern>
>         </servlet-mapping>
>
>         <resource-ref>
>           <res-ref-name>jdbc/test_connect</res-ref-name>
>           <res-type>javax.sql.DataSource</res-type>
>           <res-auth>Container</res-auth>
>         </resource-ref>
> </web-app>
>
> server.xml <Context>:
>   <Context path="/testConnectionPooling"
> docBase="testConnectionPooling" debug="0" reloadable="true">

<Resource name="jdbc/test_connection" auth="Container"
type="javax.sql.DataSource"/>
is missing

>     <ResourceParams name="jdbc/test_connect">
>       <parameter>
>         <name>username</name>
>         <value>informix</value>
>       </parameter>
>       <parameter>
>         <name>password</name>
>         <value>informix</value>
>       </parameter>
>       <parameter>
>         <name>driverClassName</name>
>         <value>com.informix.jdbc.IfxDriver</value>
>       </parameter>
>       <parameter>
>         <name>url</name>
> <value>jdbc:informix-sqli://url:port/dbName:INFORMIXSERVER=serverName</value>
>       </parameter>
>     </ResourceParams>
>   </Context>
>
> .java:
> import java.io.*;
> import java.sql.*;
> // -Must import javax.naming use JNDI which is required to implement data
> //   resource references and hence connection pooling.
> import javax.naming.*;
> import javax.sql.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.util.*;
>
> public class TestConnectionPooling extends HttpServlet {
>         private DataSource dataSource;
>
>         public void init(ServletConfig config) throws ServletException {
>                 try {
>                         Context init = new InitialContext();
>                         // don't know what the 'java:comp/env' refers to
>                         Context ctx = (Context) init.lookup("java:comp/env");
>                         // I know "jdbc/conversion must match the web.xml res-ref-name
of
> the web.xml but don't know what the path really refers to
>                         dataSource = (DataSource) ctx.lookup("jdbc/test_connect");
>                 } catch (NamingException ex) {
>                         throw new ServletException("Cannot retrieve
> java:comp/env/jdbc/test_connect",ex);
>                 }
>         }
>
>         public void doGet(HttpServletRequest request, HttpServletResponse response)
>         throws ServletException, IOException {
>                 response.setContentType("text/html");
>                 PrintWriter out = response.getWriter();
>                 Connection connection = null;
>                 out.println ("<HTML><HEAD><TITLE>Test Connection
> Pooling</TITLE></HEAD><BODY>");
>                 out.println("<H1>Customer Name Query</H1>");
>
>                 try {
>                         synchronized(dataSource) {
>                             connection = dataSource.getConnection();
>                         }
>                         out.println("<br>");
>                         out.println("<strong>Loaded informix driver successfully
via
> server.xml.</strong>" +
>                                                 "Now attempting db connection.");
>                         out.println("<br>");
>                         PreparedStatement pstmt = connection.prepareStatement("SELECT
blah
> FROM blah blah");
>                         ResultSet results = pstmt.executeQuery();
>                         if (!results.next()) {
>                                 throw new SQLException("No data returned for some reason");
>                         }
>                         out.println("<br>");
>                         while(results.next()) {
>                                 out.println("<tr><td>" + results.getString("blah")
+ "</td></tr>");
>                         }
>         } catch (Exception ex) {
>                         out.println("<br>");
>                         out.println("Exception: " + ex);
>                         if(ex instanceof SQLException) {
>                                 SQLException sqlex = (SQLException) ex;
>                                 out.println("<br>");
>                                 out.println("SQL state: "+sqlex.getSQLState()+"<BR>");
>                                 out.println("<br>");
>                                 out.println("Error code: "+sqlex.getErrorCode()+"<BR>");
>                                 out.println("<br><br>");
>                                 sqlex.printStackTrace(out);
>                                 out.println("<br><br>");
>                         }
>         }
>         finally {
>             try { connection.close(); } catch (Exception ex) {}
>         }
>                 out.println ("</BODY></HTML>");
>
>
>     }
> }



On Thu, 7 Oct 2004 09:29:09 -0400, Phillip Qin
<phillip.qin@shareowner.com> wrote:
> Detail, detail, detail.
> 
> 1. your context.xml
> 2. your web.xml
> 3. how do you obtain connection from pool, java code pls.
> 4. can you connect using pool
> 5. commons-pool version
> 
> Etc. etc.
> 
> You need to provide details otherwise we can't help.
> 
> 
> 
> -----Original Message-----
> From: Eric Wulff [mailto:ewulff@gmail.com]
> Sent: October 6, 2004 5:09 PM
> To: tomcat-user@jakarta.apache.org
> Subject: connection pooling
> 
> Hi all, I have gone over some of the tomcat docs and googled errors but
> there is SO much information covering JNDI and Datasources... and I'm hoping
> I don't have to be a JNDI/Datasource and XML guru just to set up db
> connections via connection pool.
> 
> My situation is this...
> 
> System:
> Tomcat 5 on Fedora Core 2 connecting to a db on an Informix Dynamic Server
> 9.4 on Windows Server
> 
> -I am able to connect to my db via typical JDBC
> DriverManager.getConnection(). -This leads me to believe that my jdbc driver
> is in the correct place ...CATALINA
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> !DSPAM:41645f0c199801939649086!
> 
>

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


Mime
View raw message