In a java web application, a servlet has various attributes like name, initialization parameters and the context. First 2 are ok, I suppose. The context is that area of the application which can be taken as a reference to the whole application, in a way. eg: a reference in this area would be available to the whole application.
the getServletContext method of the SevletConfig interface returns the context we talked of above. A SevletConfig reference would contain the information about the servlet fetched up at the time of initialization.
They return ServletContext and servletConfig objects respectively.
ServletConfig: This is used by the container to pass information to the servlet while initializing. Information like init parameters and their values are available in this object. Info like JDBC driver name, path to database and stuffs like this can be obtained from servlet config.
In short, this gives information for a given single servlet
ServletContext: This represent the compete web application within a JVM. Typical web app containing servlets, JSPs, beans etc., run inside a single context called servlet context - a virtual wrapper. All application components can get their initialisation parameters, application attributes etc., from this object.
I short this allows application components to interact with each other and fetch application wide info from the container.
So,we can say that servletconfig is verymuch related to servlets and servletcontext is related to the container.
If anybody discovers that any of my statement/s to be incorrect, please do correct me.
Info like JDBC driver name, path to database and stuffs like this can be obtained from servlet config.
There are no direct APIs to this. But that's possible if you have access to DataSource object which might be initilized inside the servlet (through init params) or stored in somewhere you have access to.