The best thing about that example is that it uses a ServletContextListener instead of a load-on-startup servlet; the latter should not be used any more these days - it's an obsolete concept.
But the example completely disregards the multithreaded nature of web apps, making it a bad example indeed. If two users access the web app simultaneously, and both end up using the single DB connection, there WILL be problems.
The solution is to either a) synchronize access to the connection (thereby destroying parallel access - a bad solution), or b) to use a DB connection pool. DB pools are so easy to use that there's really no reason not to use one.