tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Atishay Kumar <atishay.ku...@gmail.com>
Subject Re: connection pooling
Date Thu, 07 Oct 2004 13:47:14 GMT
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>");
> 
> 
>     }
> }
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 


-- 
:)
Atishay Kumar
Btech, SEM VII
DA-IICT
Gandhinagar - 382009
India
ph: +91 9825383948
/****************************************************************************
 * Learn the rules as you would need them to break them properly *
 ****************************************************************************/

---------------------------------------------------------------------
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