1

I am having a bit of a problem and I was hoping someone would have an idea on where I can start on coming up with a solution. I need to create a JavaBean or JavaBean properties dynamically during program execution. I am retrieving column names from a database and then selecting those values from a specific table and I need to be able to store those values into a dynamic JavaBean. The amount of variables will change from time to time and I don't want to predefine them, because I will have to keep adding values manually to the bean for every new column added. I will also need to create the getters and setters dynamically as well, since I will be accessing the values. I looked at something called Reflection API already, but that will not work as it doesn't allow us to dynamically create the properties of the bean. Any ideas?

1
  • Did you find any of the answers helpful? Commented Jun 16, 2011 at 20:52

2 Answers 2

2

You should check out DynaBean in Apache Commons BeanUtils. It is right along the way you think about your problem.

Sign up to request clarification or add additional context in comments.

Comments

0

You could use a library like javassist to generate classes during runtime. It will allow you to add fields and methods (such as the usual getters/setters) to a class definition.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.