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”);
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 user) order by id asc “;
stmt3=conss.createstatement();
rst3=stmt3.executequery(sql3);
while(rst3.next())
{
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 user) order by id asc “;
stmt2=conss.createstatement();
rst2=stmt2.executequery(sql2);
while(rst2.next())
{
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();
http://www.bkjia.com/phpjc/508506.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/508506.htmltecharticle1 建立系统odbc 数据源photo(本次使用的是oracle 9i,详细配置如有不懂这处再和我联系) 2 编译databaseconnection.java文件 将其编译文件放入到php支持…