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+"
"+"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+"
"+"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+"
"+"arr["+i+"]=new BDSort
("+ID+","+ID2+","+NAME+",n);";
i++;
}
}
rstsss=null;
return rString;
}
public static void main(String[] args){
//測試如下
GetUserRolseArray obj1 = new GetUserRolseArray();