This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Succeeding with AI and have Veljko Krunic on-line!
See this thread for details.
Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

How can we call this method

 
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.
 
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 ]
 
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 ]
 
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.
 
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.
 
Does this tiny ad smell okay to you?
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF
htttp://www.e-iceblue.com/free-apis.html
    Bookmark Topic Watch Topic
  • New Topic