Bookmark Topic Watch Topic
  • New Topic

get the formula from database  RSS feed

 
Muhammad Shamsher Khan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hello Everybody!

I hope that all you will be fine. My Question is with reference of java.

I want to define formula in database and access by the rs.getString("") in java class and execute.

for example:

"(a * b)/c*100"


public int myFormul()
{
int a = 32, b = 20, c = 2,result = 0;
try
{
String Str_Variable = rs.getString("");
result = Str_Variable;
System.out.println(result);
}
}


How is it possible in java? please write any example for it.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16045
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
There is no easy way to execute an expression that is stored in a string.

In purely interpreted scripting languages you can often do this easily, but Java is not a scripting language.

You will need to parse the formula yourself and compute it. There are some libraries available which allow you to use Java as a kind of scripting language, like BeanShell.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Report post to moderator
Muhammad, please stop posting the same question several times in this and other forums. Now there are answers in several forums, which duplicates peoples time and effort, and makes it harder to find and keep track of the topic.
[ January 26, 2006: Message edited by: Ulf Dittmer ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please continue discussion here: http://www.coderanch.com/t/378959/java/java/send-formula-another-place
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!