1. create the ODBC data source photo (Oracle9i is used this time. if you do not understand the detailed configuration, contact me again) 2. compile DataBaseConnection. the java file puts the compiled file into the class file directory supported by PHP packagecom. inberkong. util ;/***********************************
1. create the ODBC data source photo (this time we use Oracle 9i. if you do not understand the detailed configuration, contact me again)
2. Compile the DataBaseConnection. java file and put it into the class file directory supported by PHP.
Package com. inberkong. util;
/*************************************** ****************
* Programe File: duplicate buffer pool 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
// A tool class used to find data sources.
**************************************** ***************/
Import java. SQL .*;
// Tool used to connect to the database.
Public class DataBaseConnection
{
/**
* A static method returns a database connection.
*/
Public static Connection getConnection ()
{
Connection con = null;
Try
{
Class. forName ("sun. jdbc. odbc. JdbcOdbcDriver ");
Con = DriverManager. getConnection ("jdbc: odbc: photo", "photo", "inberkong"); // data source connection information
}
Catch (Exception e)
{
E. printStackTrace ();
}
Return con;
}
}
3. the processing class for compiling and reading data tables also puts the processing class into the Java class directory called by PHP.
This is a processing class of the JS array that reads the user role table and returns the relationship between the user and the role. GetUserRolseArray. java
Note: When reading a program, you do not need to care about the related table structure. you can only care about the entire calling process.
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 ";
// External users are not involved in the add-on role management
Stmtsss = conss. createStatement ();
Rstsss=stmtsss.exe cuteQuery (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.exe cuteQuery (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.exe cuteQuery (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 ){
// The test is as follows:
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 call
Testjava. php
$ B = new Java ("com. inberkong. processBean. GetUserRolseArray ");
$ X = $ B-> getUserRolseArray ();
Echo $ x;
?>
Call result:
Arr [0] = new BDSort ('000000', '00', 'dp2 ','');
Arr [1] = new BDSort ('44', '123', 'shop Postmaster ', 'y ');
Arr [2] = new BDSort ('42', '123', 'super admin', 'n ');
Arr [3] = new BDSort ('43 ', '000000', 'announcement Postmaster', 'n ');
Arr [4] = new BDSort ('87 ', '000000', 'Test common admin', 'n ');
Arr [5] = new BDSort ('20160301', '20160301', 'normal superauthorization', 'n ');
Arr [6] = new BDSort ('000000', '00', 'dp1 ','');
Arr [7] = new BDSort ('44', '123', 'shop Postmaster ', 'y ');
Arr [8] = new BDSort ('42', '123', 'super admin', 'n ');
Arr [9] = new BDSort ('43 ', '000000', 'announcement Postmaster', 'n ');
Arr [10] = new BDSort ('87 ', '000000', 'Test common admin', 'n ');
Arr [11] = new BDSort ('123456', '123456', 'normal supercan', 'n ');
Arr [12] = new BDSort ('000000', '00', 'chayue ','');
Arr [13] = new BDSort ('44', '123', 'shop Postmaster ', 'y ');
Arr [14] = new BDSort ('42', '123', 'super admin', 'n ');
Arr [15] = new BDSort ('43 ', '000000', 'announcement Postmaster', 'n ');
Arr [16] = new BDSort ('87 ', '123', 'Test common admin', 'n ');
Arr [17] = new BDSort ('123456', '1234568', 'normal supercan', 'n ');
Arr [18] = new BDSort ('000000', '00', 'temp2 ','');
Arr [19] = new BDSort ('87 ', '123', 'Test common admin', 'y ');
Arr [20] = new BDSort ('42', '123', 'super admin', 'n ');
Arr [21] = new BDSort ('43 ', '000000', 'announcement Postmaster', 'n ');
Arr [22] = new BDSort ('44', '123', 'shop Postmaster ', 'n ');
Arr [23] = new BDSort ('20160301', '20160301', 'normal superauthorization', 'n ');
Arr [24] = new BDSort ('20', '00', 'cnbadmin ','');
Arr [25] = new BDSort ('42', '20', 'super admin', 'y ');
Arr [26] = new BDSort ('43 ', '20', 'announcement Postmaster', 'n ');
Arr [27] = new BDSort ('44', '20', 'shop Postmaster ', 'n ');
Arr [28] = new BDSort ('87 ', '20', 'Test common admin', 'n ');
Arr [29] = new BDSort ('123456', '20', 'normal Overview', 'n ');
Arr [30] = new BDSort ('1', '00', 'inber ','');
Arr [31] = new BDSort ('20170901', '1', 'normal supercan', 'y ');
Arr [32] = new BDSort ('42', '1', 'super admin', 'n ');
Arr [33] = new BDSort ('43 ', '1', 'announcement Postmaster', 'n ');
Arr [34] = new BDSort ('44', '1', 'shop Postmaster ', 'n ');
Arr [35] = new BDSort ('87 ', '1', 'Test common admin', 'n ');