Yes it is possible in many ways.
As some have mentioned above, Java 6 allows you to parse, manipulate and rewrite code as it is loaded!
The solution can vary:
You could for example, write your DB expression as a Java class and insert your serialized class into the DB as a glob or blob or whatever its called.
Or, you could use a template to write a Java class to a file and insert your expression into it. Then compile the class at run-time (like a JSP to Servlet) and then dynamically load the class.
Of course you'd want to cache your compiled classes for future use if they have not been edited in the database.
Then there is also the option of using an integrated scripting engine such as most of the responses have mentioned.
Whatever you choose, maybe you'll be able to update this post with details of your choice, implementation, problems, notes, comments, etc.