In terms of database connectivity it doesn't do anything
It's basically a naming service, which you could compare to DNS, if that helps?
Or even more simply you could compare its functionality to that of java.util.Map, I'm sure you're familiar with that, right?
At its core, JNDI allows you to bind an object to a unique name.
Of course that's a gross simplification, but that's the key bit of functionality.
In the context of database connectivity in a
JEE environment, the actual database connectivity is provided by JDBC, as you've stated correctly.
A DataSource is commonly used to define a target for JDBC connections and as a provider of Connection objects.
JNDI comes in to play here, by mapping a DataSource to a unique name (basically), so your application can use that name to retrieve the DataSource and get a Connection.
That's all there is to it, really. JNDI is not limited to mapping names to DataSource objects, though.
You should really have a look at
this tutorial, it describes what JNDI is in more detail, and how it can abstract access to a variety of naming services.
Edit: Ugh, Henry beat me.