国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

實戰 php調用java類由java類讀數據庫完成相關操作(Inber Write)

2024-05-04 23:04:09
字體:
來源:轉載
供稿:網友

1 建立系統odbc 數據源photo(本次使用的是oracle 9i,詳細配置如有不懂這處再和我聯系)
2 編譯databaseconnection.java文件 將其編譯文件放入到php支持的類文件目錄中

package com.inberkong.util;
/*******************************************************
 * programe file :復件緩沖池databaseconnection.java
 * creat    date :3/28/2005(mm-dd-yyyy)
 * creat by  :inberkong(gongyingbin)
 * lastmodifydate :3/28/2005(mm-dd-yyyy)
 * modifyby  :inberkong(gongyingbin)
 *  function  :get the oracle databaseconnectionpool
 //一個用于查找數據源的工具類。
 
 *******************************************************/
import java.sql.*;
//連接數據庫的工具類。
public class databaseconnection
{
 /**
  *一個靜態方法,返回一個數據庫的連接。
  */
 public static connection getconnection()
 {

  connection con=null;

     try
     {
 class.forname("sun.jdbc.odbc.jdbcodbcdriver");
       con=drivermanager.getconnection("jdbc:odbc:photo","photo","inberkong");//數據源連接信息    

  }
  catch(exception e)
  {
   e.printstacktrace();
  }
  return con;
 }
}

3 編譯讀數據表的處理類同樣將處理類放入php調用的java類目錄
這是一個讀取用戶角色表 返回用戶與角色間關系的js數組的處理類 getuserrolsearray.java
注:讀程序時不需要關心相關的表結構,可只關心整個調用的處理過程。
package com.inberkong.processbean;
import java.lang.*;
import java.sql.*;
import java.util.*;
import java.io.*;
import com.inberkong.util.databaseconnection;
public  class getuserrolsearray
{
 private connection conss;
 private statement stmtsss=null;
 private statement stmt2=null,stmt3=null;
 private resultset rstsss=null;
 private resultset rst2=null,rst3=null;
    private string sqlss="";
    private string sql2="",sql3="";
    private string rstring="";
    private string id,id2;
    private string name;
    private int i=0;
 public getuserrolsearray()
 {
  try
  { 
 
  this.conss=databaseconnection.getconnection();
     }
    catch(exception e)
    {
    
    }

  //databaseconnection.getconnection();
 }
 protected void finalize() throws throwable
 {
 
  //
 //super.finalize(); 
 //system.out.println("inberkong");
 closecon();
 
 }      
   public  string  getuserrolsearray() throws exception
     {
      //exeptempfunction();
     
      sqlss="select id,name from admin where 1=1 and state!=0 and  usertype!='0'

order by id desc";     
      //外部用戶不參于后加角色管理
      stmtsss=conss.createstatement();
      rstsss=stmtsss.executequery(sqlss);    
      while (rstsss.next())
      {
       id=rstsss.getstring("id");
       id2=id;
      
       name=rstsss.getstring("name");
       rstring=rstring+"/n"+"arr["+i+"]=new bdsort

('"+id+"','00','"+name+"','');";
       i++;
      
       sql3="select id,name from role_manage  where id in( select rolseid

from user_rolse_link where userid="+id2+") order by id asc ";
       stmt3=conss.createstatement();
       rst3=stmt3.executequery(sql3);
       while(rst3.next())
       {
      
       id=rst3.getstring("id");
            
       name=rst3.getstring("name");
       rstring=rstring+"/n"+"arr["+i+"]=new bdsort

('"+id+"','"+id2+"','"+name+"','y');";
        i++;       
       }
             
       sql2="select id,name from role_manage  where id  not in(select

rolseid from user_rolse_link where userid="+id2+") order by id asc ";
       stmt2=conss.createstatement();
       rst2=stmt2.executequery(sql2);
       while(rst2.next())
       {
      
       id=rst2.getstring("id");
            
       name=rst2.getstring("name");
       rstring=rstring+"/n"+"arr["+i+"]=new bdsort

('"+id+"','"+id2+"','"+name+"','n');";
        i++;       
       }

 
      }
 
     rstsss=null;
     return rstring;

     }
    
    
     public static void main(string[] args){
    
     //測試如下
        getuserrolsearray obj1 = new getuserrolsearray();
       
          try
  { 
 
        system.out.println(obj1.getuserrolsearray());
 
     }
    catch(exception e)
    {
    //system.out.println(e);
    }

        return;
    }
     
   public void closestmtsss()throws exception
   {
   stmtsss.close();
   }
   public  void closecon() throws exception
   {
    if(!(conss.isclosed()))
    conss.close();
   
   }
}
4 php調用

testjava.php

<?php
$b=new java("com.inberkong.processbean.getuserrolsearray");
$x=$b->getuserrolsearray();
echo $x;
?>
調用結果:
arr[0]=new bdsort('186','00','dp2','');
arr[1]=new bdsort('44','186','店鋪管理員','y');
arr[2]=new bdsort('42','186','超級管理員','n');
arr[3]=new bdsort('43','186','公告管理員','n');
arr[4]=new bdsort('87','186','測試普通管理員','n');
arr[5]=new bdsort('106','186','普通超管','n');
arr[6]=new bdsort('185','00','dp1','');
arr[7]=new bdsort('44','185','店鋪管理員','y');
arr[8]=new bdsort('42','185','超級管理員','n');
arr[9]=new bdsort('43','185','公告管理員','n');
arr[10]=new bdsort('87','185','測試普通管理員','n');
arr[11]=new bdsort('106','185','普通超管','n');
arr[12]=new bdsort('146','00','chayue','');
arr[13]=new bdsort('44','146','店鋪管理員','y');
arr[14]=new bdsort('42','146','超級管理員','n');
arr[15]=new bdsort('43','146','公告管理員','n');
arr[16]=new bdsort('87','146','測試普通管理員','n');
arr[17]=new bdsort('106','146','普通超管','n');
arr[18]=new bdsort('145','00','temp2','');
arr[19]=new bdsort('87','145','測試普通管理員','y');
arr[20]=new bdsort('42','145','超級管理員','n');
arr[21]=new bdsort('43','145','公告管理員','n');
arr[22]=new bdsort('44','145','店鋪管理員','n');
arr[23]=new bdsort('106','145','普通超管','n');
arr[24]=new bdsort('20','00','cnbadmin','');
arr[25]=new bdsort('42','20','超級管理員','y');
arr[26]=new bdsort('43','20','公告管理員','n');
arr[27]=new bdsort('44','20','店鋪管理員','n');
arr[28]=new bdsort('87','20','測試普通管理員','n');
arr[29]=new bdsort('106','20','普通超管','n');
arr[30]=new bdsort('1','00','inber','');
arr[31]=new bdsort('106','1','普通超管','y');
arr[32]=new bdsort('42','1','超級管理員','n');
arr[33]=new bdsort('43','1','公告管理員','n');
arr[34]=new bdsort('44','1','店鋪管理員','n');
arr[35]=new bdsort('87','1','測試普通管理員','n');

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 彭阳县| 石城县| 沙坪坝区| 佛学| 成都市| 宁远县| 奇台县| 饶平县| 鄂托克旗| 玉龙| 荣昌县| 开封市| 宁夏| 惠州市| 中阳县| 故城县| 台南县| 泸水县| 江油市| 三明市| 宝坻区| 门头沟区| 柳江县| 中西区| 商河县| 获嘉县| 旬邑县| 临西县| 凌海市| 太和县| 郯城县| 贵溪市| 宁晋县| 丰顺县| 赤城县| 金沙县| 庆元县| 汕尾市| 三都| 平定县| 江源县|