• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

How can we call this method

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hands up, anyone?
 
Bimal Patel
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic