Home > php教程 > php手册 > body text

实战php调用java类由java类读数据库完成相关操作(Inber Write)

WBOY
Release: 2016-06-21 09:08:44
Original
890 people have browsed it

数据|数据库

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++;       
       }
 

[1] [2] 下一页  



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template