i have it setup for sybase and mine looks like this in the server.xml: --------------------------------------------------------------------------------- <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?JCONNECT_VERSION=6</value> </parameter> <parameter> <name>username</name> <value>your_userid</value> </parameter> <parameter> <name>password</name> <value>your_password</value> </parameter> </ResourceParams> </Context> --------------------------------------------------------------------------------- of course i also got a .jar file (jConnect 5.5) from sybase that i guess provides the "com.sybase.jdbc2.jdbc.SybDriver" and then in the JSP u have something like this to reference the context and setup the connection: --------------------------------------------------------------------------------- String s = "java:comp/env"; String t = "jdbc/a_sybase_datasource"; InitialContext initCtx = null; try { initCtx = new InitialContext(); } catch(Exception e) { out.println("<BR />"); out.println("<BR />"); out.println("<PRE>failed: initCtx = new InitialContext();"); out.println(e + " : " + e.getMessage()); out.println("</PRE><BR />"); } Context envCtx = null; try { envCtx = (Context)initCtx.lookup(s); } catch(Exception e) { out.println("<BR />"); out.println("<BR />"); out.println("<PRE>failed: envCtx = (Context)initCtx.lookup(" + s + ");"); out.println(e + " : " + e.getMessage()); out.println("</PRE><BR />"); } DataSource ds = null; try { ds = (DataSource)envCtx.lookup(t); } catch(Exception e) { out.println("<BR />"); out.println("<BR />"); out.println("<PRE>failed: ds = (DataSource)envCtx.lookup(" + t + ");"); out.println(e + " : " + e.getMessage()); out.println("</PRE><BR />"); } if(ds == null) { out.println("<BR />"); out.println("<BR />"); out.println("<PRE>warning: DataSource is null"); out.println("</PRE><BR />"); } Connection conn; Statement stmt; ResultSet rs; // open connection object conn = ds.getConnection(); // open statement object stmt = conn.createStatement(); --------------------------------------------------------------------------------- Thanks, Alan Czajkowski ------------------------------------- Database Administrator BMO Financial Group Decision Support Services 3300 Bloor Street West 14th Floor, West Tower Toronto, Ontario, M8X 2X2 Tel: 416.232.8736 ------------------------------------- "Hart, Justin" <[EMAIL PROTECTED]> 16/12/2003 02:26 PM Please respond to "Tomcat Users List" To: "Tomcat Users List" <[EMAIL PROTECTED]> cc: Subject: RE: JDBC from TagSupport Ok, so, how does one access this datasource from tagsupport? Justin -----Original Message----- From: Philipp Taprogge [mailto:[EMAIL PROTECTED] Sent: Tuesday, December 16, 2003 2:24 PM To: Tomcat Users List Subject: Re: JDBC from TagSupport Hi! Hart, Justin wrote: > Quick question. I see that one can configure a JDBC datasource in their server.xml file and their web.xml file. > What does this get you? Every example that I have read tells me that I need to open a JDBC connection just about > the same as I would from any other java application. > > What is the purpose of setting up a JDBC datasource in these files? Is it only good for userdatabaserealm? The main advantage is that you can use a connection pool like jakarta-commons-dbcp which saves you a lot of runtime. The second advantage is that you can configure the connection parameters like db URL, username, password and the like on the fly without editing java sources or redeploying your application. Phil --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]