I think you can do that,As you know that we have TimerService in EJB 2.1 ownward,which can run automatically on given time period.
So you can use TimeService as background process which keep testing your data base status,if the data base is down that you can undeploy the MDB.
You need to pack your MDB as a seperate JAR file,so that when you deploy/un-deploy other component will not get effected.
And you need to explorer how you can deploy/undeploy JAR files on different conatiners.
But I can give to some start point so that you can start as far as deployment/un-deployment is concern.
If you go to your application server amin page,where you can deploy/un-deploy your EJB,just place the mouse over the link than It will show what url is being invoked.
e.g. in Tomcat if you want to stop any context than http://<host>:<port>/manager/html/stop?path=<context
name> is used
and we can achive using simple java code which make connection to given url and stop the context.
So when the timer service came to know that database is down than it will undeploy your MDB and when DB is back than it will deploy the MDB.
Hope that this will help you.