doutao1282 2013-11-16 01:47
浏览 25
已采纳

从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?

  • 写回答

2条回答 默认 最新

  • douge3830 2013-11-16 02:26
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?