• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can we call this method  RSS feed

 
Babar Qadri
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a method in my class. But I dont want to call it straight. Infact, I am getting the method call from database as a string. The string looks like, "classA.calculate(valueA)".

I get this method call, statement, as string using rs.getString(). Is there any way to execute this statement?

Thanks.
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you considered using reflection (java.lang.reflect). There is a class named Method, and it has an invokeMethod.


Look at this example. In this case I suppose you have already loaded the necesary classes, if it is not your case, you will have to load them using, for instance, a java.net.URLClassLoader.


[ January 16, 2006: Message edited by: Michael Ernest ]
 
Bimal Patel
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I think its possible by using "Class" class. What do you think guys?
[ January 16, 2006: Message edited by: Bimal Patel ]
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You many really *need* to store code in your database, but: hands up, how many forum members have needed to do that? What problem are you trying to solve? Perhaps there's a simpler way to do it.
 
Rick O'Shay
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Babar Qadri:
I have a method in my class. But I dont want to call it straight. Infact, I am getting the method call from database as a string. The string looks like, "classA.calculate(valueA)".

I get this method call, statement, as string using rs.getString(). Is there any way to execute this statement?

Thanks.


"Why"? He dared ask.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hands up, anyone?
 
Bimal Patel
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Whenever there is a need to bind properties with java bean components, and such binding should be custom based, one needs to use reflection API. I think while you're involved in any of the framework creation, that may need.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!