Problem Description: How do you configure jConnect JDBC Connection Pooling with Apache Tomcat 4.1.x?
Tip or Workaround: (Observations performed with jConnect-5_2 and Tomcat 4.1.18)
In line, below, are the text of what should be saved as 3 files:
web.xml sybase.jsp server.xml.SybaseDelta
Please proceed as follows:
1) Create the following folders: 1.1) C:\Program Files\Apache Group\Tomcat 4.1\webapps\sybase 1.2) C:\Program Files\Apache Group\Tomcat 4.1\webapps\sybase\jsp 1.3) C:\Program Files\Apache Group\Tomcat 4.1\webapps\sybase\WEB-INF 1.4) C:\Program Files\Apache Group\Tomcat 4.1\webapps\sybase\WEB-INF\jsp
2) Move the file "web.xml" to folder C:\Program Files\Apache Group\Tomcat 4.1\webapps\sybase\WEB-INF
3) Move the file "sybase.jsp" to folder C:\Program Files\Apache Group\Tomcat 4.1\webapps\sybase\jsp
4) Copy the contents of file "server.xml.SybaseDelta" into your existing "C:\Program Files\Apache Group\Tomcat 4.1\conf\server.xml" file.
Insert the new content as an additional context within the "Tomcat-Standalone" service specification. Insert this after the last "</context>" entry, but before the "</host>" terminator in the "Tomcat-Standalone" service grouping.
Replace the following strings with values appropriate to your installation:
database_hostname your_dbname your_userid your_password
If your dataserver is not "listening" on port 5000, make the corresponding change for the port, too, in the connection url.
5) Copy your jConnect\classes\jconn2.jar file into directory C:\Program Files\Apache Group\Tomcat 4.1\common\lib
6) Shutdown and restart Tomcat.
7) From your web browser, enter the following url:
http://localhost:8080/Sybase
-----------------------------------------------------------
Text of file "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>
<welcome-file-list> <welcome-file> /jsp/sybase.jsp </welcome-file> </welcome-file-list>
<!-- for using dscp -->
<resource-ref> <res-ref-name> jdbc/a_sybase_datasource </res-ref-name> <res-type> javax.sql.DataSource </res-type> <res-auth> Container </res-auth> </resource-ref>
</web-app>
END_OF_TEXT(web.xml)
Text of file "sybase.jsp" -------------------------
<%@ page import="java.sql.*" %> <%@ page import="javax.sql.*" %> <%@ page import="javax.naming.*" %> <%@ page import="java.util.*" %>
<html> <head> <title> Testing Sybase DataSource </title> </head>
<body bgcolor="white"> <font size=4>
<h3> Start of Test </h3>
<%
String s = "java:comp/env"; String t = "jdbc/a_sybase_datasource";
InitialContext initCtx = null; try { initCtx = new InitialContext(); out.println("<p>initCtx = new InitialContext() : successful"); out.println("<BR>"); out.println( initCtx ); } catch (Exception e) { out.println("<p>initCtx = new InitialContext() : failed"); out.println("<BR>"); out.println ( e ); }
Context envCtx = null; try { envCtx = (Context) initCtx.lookup( s ); out.println("<BR>envCtx = initCtx.lookup(" + s + ") : successful"); out.println("<BR>"); out.println( envCtx ); } catch (Exception e) { out.println("<BR>envCtx = initCtx.lookup(" + s + ") : failed"); out.println ( e ); }
DataSource ds = null;
ds = null; try { out.println("<p>Trying ds=(DataSource)envCtx.lookup(" + t + ")"); ds = (DataSource) envCtx.lookup( t ); out.println("<BR>DataSource lookup apparently successful"); out.println("<BR>" + ds ); } catch (Exception e) { out.println("<BR>Datasource lookup failed <BR>"); out.print( e ); }
if (ds == (DataSource) null) { out.println("<BR>DataSource null\n"); }
try {
Connection conn = ds.getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select db_name()"); while (rs.next()) { out.println ( "<BR>Inside fetch loop:" ); out.println ( "<BR>Value Returned from DataSource: " + rs.getString(1) ); } // end_while
rs.close(); stmt.close(); conn.close(); } // end_try catch (SQLException sqe) { out.println("<BR>Inside catch(SQLException sqe)"); out.println( sqe.getMessage() ); } // end catch SQLException catch (Exception e) { out.println("<BR>Inside catch(Exception e)<BR>"); out.println(e.getMessage()); out.print( e ); } // end catch Exception %>
<p> <h3> End of Test </h3> </font> </body> </html>
END_OF_TEXT(sybase.jsp)
Text of file "server.xml.SybaseDelta" -------------------------------------
<!-- Sybase Example Context - dscp example -->
<Context path="/Sybase" docBase="sybase" debug="5" reloadable="true" crossContext="true">
<Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_Sybase.log." suffix=".txt" timestamp="true"/>
<Resource name="jdbc/a_sybase_datasource" auth="Container" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/a_sybase_datasource">
<parameter> <name>factory</name> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> </parameter>
<parameter> <name>maxActive</name> <value>10</value> </parameter>
<parameter> <name>maxIdle</name> <value>5</value> </parameter>
<parameter> <name>maxWait</name> <value>10000</value> </parameter>
<parameter> <name>driverClassName</name> <value>com.sybase.jdbc2.jdbc.SybDriver</value> </parameter>
<parameter> <name>url</name> <value>jdbc:sybase:Tds:database_hostname:5000/your_dbname</value> </parameter>
<parameter> <name>username</name> <value>your_userid</value> </parameter>
<parameter> <name>password</name> <value>your_password</value> </parameter>
</ResourceParams> </Context>
<!-- END Sybase Example Context - dscp example -->
END_OF_TEXT(server.xmlSybaseDelta)
Resolution: j"Tips and Workarounds", above, describes an example Sybase datasource definition, complete with a test jsp.

|