• 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:

Embedding Jython in JAVA Application

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have written a program in which Jython code is executed to query a database and result is converted to a String and then displayed.

The problem I am facing is that the criteria for the query is a String in java and I have to pass that variable to Jython code before the query is processed. Here is the code:

public class SimpleEmbedded {
public static void main(String []args)
throws PyException
{
PythonInterpreter interp =new PythonInterpreter();

String ip_address = "12.12.12.12";


interp.exec("import xmlrpclib");

interp.exec("fathomServer = xmlrpclib.Server(\"http://fathom.software.att.com:8000\" )");
interp.exec("reply = fathomServer.ipWhois(12.12.12.12)");
PyObject x = interp.get("reply");
String fathom = x.toString();

Now in the code the query ipWhois needs an IP Address as input. Right now it is hard coded and working fine but I need to pass a variable there.

I have not been able to find a way to replace hardcoded IP Address with a string variable.

So I need a way to pass java variable to jython.
Please help?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
interp.exec("reply = fathomServer.ipWhois(" + ip_address + ")");
 
Nee Kat
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks alot!
It worked.
 
reply
    Bookmark Topic Watch Topic
  • New Topic