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');
新闻热点
疑难解答