Well, as far as *I* think, bringing error messages from database is not a good idea. Talking to databse requires heavy use of resources and an error situation in itself lead to resource locking (at times, not necessarily).
So, on the first *I* feel it would be a bad coding practice and moreover, a bad idea as well when we have message resource file.
But, somehow we we have a constraint to get the error messages from database then too the process goes the same way. Ideal practice will be to make your own exception handler which will fill the messages from database. Once you get an error and reach the catch block. Just bundle that exception in your custom exception type and call your exception handler.
Another way(but, it's exhaustive) yet bad, is to get all mesasages from DB and store in some temporary session variable and use it appropriately.
Whatever be the case, *I* still feel weird about it and suggest to stick to message resource file.