Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
    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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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: 43028
76
  • 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
 
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic