Hey,
Ya - confusing is about it.
I found another better solution using Tomcat Admin meantime, but first......
To explain, we all seem to be be looking at the section "MySQL DBCP Example" in
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html, or possibly earlier versions of the same information. This is where we all seem to get our SQL to set up the "javatest" database, plus the "DBTest" Context definition, web.xml, and test.jsp. Re. my using "javatest" instead of "TestDB" I get confused when I see labels like "TestDB" and "DBTest" in the same examples, and I changed "TestDB" to "javatest" thinking it might be that simple. Otherwise everything is the same in my Context and web.inf as in the examples, or it was until....
While fiddling about with this some more (well, a LOT more):
- I got an error that my web.xml file was missing: it was and I reinstated it. This was just a user error tho'.
- Originally I had put my DBTest Context ahead of the closing Server tag in server.xml which of course is entirely the wrong place for it especially with Tomcat 5.5 and it now lives where it should under $CATALINA_HOME/conf/Catalina/localhost as DBTest.xml. At this stage it was stil the same code as the example only with "TestDB" changed to "javatest".
- At this time I noticed in Tomcat Admin that the app's Datasource was listed as a global Datasource with all fields correctly filled in, whereas the Datasource under Host/localhost-Context/DBTest was incomplete (no driver name, database URL, username or password), and I got: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver".
- I tried to fix this by creating DBTest.xml in ./conf/Catalina/localhost, and using the default server.xml at the same time. Upon restart Tomcat Admin now showed the Datasource absent from the global list and present but still incomplete under Host(localhost)/DBTest/Datasources, and I got the original "Datasource invalid ... NULL pointer" error back again.
- Next, I found that if I used Tomcat Admin to enter the missing information in the localhost/DBTest JNDI Datasource, reloaded the DBTest app from Tomcat Manager, and then ran the original test.jsp it worked properly.
- Lastly I noticed that using Tomcat Admin to "Commit changes" saved a copy of server.xml and wrote a new one as follows, after which on restart the "Datasource invalid..NULL" error was still gone with the original test.jsp now working as it should.
Here is my new server.xml:
- Last but not least, it turns out that not only was server.xml rewritten, but so were all the files in ./conf/Catalina/localhost: DBTest.xml, admin.xml, host-manager.xml, and manager.xml.
Here they all are:
New DBTest.xml:
New admin.xml:
New host-manager.xml:
New manager.xml:
Since you asked, here is my original Context ("TestDB" changed to "javatest" only):
And here is my web.xml file (same change):
Phew! Now I've written all that down I must have another cup of tea.