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条)

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向