Actual combat PHP Invoke Java class to complete related operations by Java class Read database (Inber Write)

Source: Internet
Author: User
Tags odbc
Data | database

1 Establish the System ODBC data source photo (this time using Oracle 9i, detailed configuration if you do not understand this place and I will contact)
2 Compile the Databaseconnection.java file and put it into the PHP-supported class file directory

Package com.inberkong.util;
/*******************************************************
* Programe File: Complex 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 for locating data sources.

*******************************************************/
Import java.sql.*;
A tool class that connects to a database.
public class DatabaseConnection
{
/**
* A static method that returns a connection to a database.
*/
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 that compiles and reads the data table also puts the processing class into the Java class directory of the PHP invocation
This is a processing class that reads the User Role table returns a JS array of relationships between the user and the role Getuserrolsearray.java
Note: The reading program does not need to care about the related table structure, can only care about the entire call 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 user does not participate in post plus role management
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+ ', ', ', ' +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] Next page



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.