I've got database access working in two more ways, though the original problem remains.
1) Adding a <ResourceLink> to /template via the admin app. 2) Adding a <DefaultContext> tag to conf/server.xml, with the <ResourceLink>s inside. (I tried 3) adding the <ResourceLink> to the "/" context, but it wasn't visible in /template). The problem with 1 is that the change is written to conf/Catalina/localhost/template.xml, and doesn't survive 'ant remove'/'ant deploy'. I could leave it 'just so', but that adds a manual step to deployment on different servers that defeats the purpose of ant automation. The problem with 2 is that the <DefaultContext> shows up in the admin app under Service (Catalina), but clicking on it returns an error page. The db access continues to work, but server.xml can no longer be maintained through the admin app. So, the solution to this problem looks like one of two things: either knowing where to put the <Context> fragment in my project so that it survives deployment; or correctly adding a <DefaultContext> to <Engine> or <Host> in server.xml that doesn't break the admin app. An interesting point about the second option: There's no way to add <DefaultContext> to server.xml through the admin app that I can find--the actions available under Server (Catalina) don't include it. -----Original Message----- From: Justin Johnson [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 25, 2004 3:18 PM To: 'Tomcat Users List' Subject: A tangled knot: db, resources, Context, ant deploy, and Tomcat 5. 0.16-19 It starts with this error message: "Cannot create JDBC driver of class '' for connect URL 'null', cause: No suitable driver". I have Tomcat 5.0.19 installed on Windows XP Professional--a default install from the binary, changing only one thing, the port from 8080 to 80. I copy my extra jars (JsqlConnect, mail.jar, JSTL jars, and JCIFS) into common/lib. Start it, runs fine, including management and admin apps. I build my template app following the developers guide: ant, cvs, directory structure. Put index.jsp and Hello.java in, 'ant deploy', both work correctly at "/template". Need database access. Go to admin app, add global datasources that put the following into conf/server.xml (stuff in [] is hidden stuff): <Resource name="jdbc/[server]" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/[server]"> <parameter> <name>maxWait</name> <value>5000</value> </parameter> <parameter> <name>maxActive</name> <value>4</value> </parameter> <parameter> <name>password</name> <value>[password]</value> </parameter> <parameter> <name>url</name> <value>jdbc:JSQLConnect://[server].[domain].com/</value> </parameter> <parameter> <name>driverClassName</name> <value>com.jnetdirect.jsql.JSQLDriver</value> </parameter> <parameter> <name>maxIdle</name> <value>2</value> </parameter> <parameter> <name>username</name> <value>[username]</value> </parameter> </ResourceParams> In my web.xml I have, first thing under <web-app>: <resource-ref> <res-ref-name>jdbc/[server]</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> I add the following to index.jsp: <% Context ctx = new InitialContext( ) ; DataSource ds = (DataSource) ctx.lookup( "java:comp/env/jdbc/[server]" ) ; Connection con = ds.getConnection( ) ; Statement st = con.createStatement( ) ; ResultSet rs = st.executeQuery( "SELECT 1 + 1 [Sum]" ) ; if( rs.next( ) ) out.println( rs.getString( "Sum" ) + "<br />" ) ; rs.close( ) ; st.close( ) ; con.close( ) ; %> And get the error mentioned above: "Cannot create JDBC driver of class '' for connect URL 'null', cause: No suitable driver". I change index.jsp to: <% Class.forName( "com.jnetdirect.jsql.JSQLDriver" ).newInstance(); Connection con = DriverManager.getConnection( "jdbc:JSQLConnect://[server].[domain].com/", "[username]", "[password]" ) ; Statement st = con.createStatement( ) ; ResultSet rs = st.executeQuery( "SELECT 1 + 1 [Sum]" ) ; if( rs.next( ) ) out.println( rs.getString( "Sum" ) + "<br />" ) ; rs.close( ) ; st.close( ) ; con.close( ) ; %> And it works fine, including retrieving a recordset by query. So I find template.xml in conf/Catalina/localhost and paste the <Resource> and <ResourceParams> tags into it inside the <Context> tag, and go back to the first version of my database access code in index.jsp, 'ant reload'. Works fine. I'd like to use ResourceLink instead, but it's working. The problem is that when I undeploy and redeploy /template, /conf/Catalina/localhost/template.xml is overwritten with a fresh copy that contains an empty <Context> tag except for path and docBase attributes (the ant deploy task specifies a localwar, which simply adds the path to my working copy/build to docBase). Reading the configuration guidelines for contexts at http://jakarta.apache.org/tomcat/tomcat-5.0-doc/config/context.html, I think I should put the context xml fragment into a file context.xml in META-INF. But when I do so, I still get the empty, auto-generated <Context> in template.xml in conf/Catalina/localhost. When I change the deploy task in build.xml to copy a war to [tomcat]/webapps, I get no template.xml file, and no database access, as if my context.xml file is not being picked up. All this time, normal jsp stuff like <c:out value="${ 'webapp working' }" /> continues to function correctly, and I'm having no problems deploying, undeploying, or reloading. So, the problem as it seems to me is one or both of the following: 1) I don't know where to put my <Context> fragment for it be picked up by ant deploy/Tomcat, which seems to be ignoring it and using a default generated <Context>; 2) I'm missing something in web.xml or my deploy configuration in build.xml that will prefer my <Context> fragment. Ideally, the datasources should be available server wide. Where then would I put the <ResourceLink> tags so that all applications can get at them? Anyone who can help me out here will be greatly appreciated. Justin --------------------------------------------------------------------- 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]
