I want to know if there is any way to convert a String to Java compilable code.
I have a comparative expression saved in a database field. I want to re
If you're getting the condition from a database, I'll wager there's a good chance that you might be wanting to use that condition to access data in that database.
If you're using an ORM such as JPA or Hibernate (traditional or JPA), you might be able to formulate a dynamic query expression that you'd pass to the createQuery() method. This isn't as good as being able to do an on-the-fly compile of arbitrary Java code, but maybe it's all you need, and that particular solution doesn't require any special inclusions or actions, since the query language compiler is part of the ORM system itself.
Of course, if you DO do dynamic queries that way, I'd recommend logging them somehow, since it can be a real pain to figure out what went wrong after the fact if your query string is now in the garbage collector.