从php调用外部java类[关闭]

I'm starting a website project that requires to communicate with external oracle databases. The oracle databases are managed by a system written in java. I was wondering if it is possible for me to use those java classes from within a website using php.

As an example i'm trying to achieve something like : shell_exec("path/java GetSomething") but with the "path/java" stored on a remote server.

Am I giving this the right approach? will this cause security issues?

One way to do it would be to make a JSP web service consumable by php. This is a very basic start, but the idea is, you have a jsp which lives on the java server, and it can be called over the web. It takes parameters, then hits the database with those parameters, and returns it. PHP makes a call to this service and reads the data it returns.

DatabaseService.jsp

String query = Request.getParameter('query');
ResultSet rs = MyDbClass.executeQuery(query);


ResultSetMetaData rsmd = rs.getMetaData();
int colCount           = rsmd.getColumnCount();

while (rs.next())
{
    for (int i = 1; i <= colCount; i++)
    {
        String columnName = rsmd.getColumnName(i);
        Object value      = rs.getObject(i);
        out.println(columnName+":"+value.toString()+'\t');
    }
    out.println("
");
}

oracleConnect.php

$query=urlencode("SELECT * FROM DB.table");
$results=file_get_contents("http://remoteServer.com/DatabaseService.jsp?query=$query");

This is highly simplified, you will need to output the data some way consumable by php like xml, as well as sending other parameters, an api key, using CURL instead of file_get_contents, any number of things, but this basic model should get you started in the right direction.

Am I giving this the right approach?

No. It won't work. You can't just "run a shell command on another server". Certainly, you can't do it unless you have set up a bunch of infrastructure to support this.

will this cause security issues?

That would be a concern you would need to address.


The real problem here is that your "problem description" is too vague to understand whether what you are trying to do makes any sense ... from the technical, architectural and practical points of view.