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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

get the formula from database

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please continue discussion here: https://coderanch.com/t/378959/java/java/send-formula-another-place
    Bookmark Topic Watch Topic
  • New Topic