Home >Database >Mysql Tutorial >树形结构的实现

树形结构的实现

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 15:12:291054browse

本例采用access做为实例,所有还有很多要改进的地方。 请读者自已改进 packagePRodUCt; importjava.sql.*; publicclassConnectDB{ StringstrDBDriver=sun.jdbc.odbc.JdbcOdbcDriver; StringstrConnstr=jdbc:odbc:product; Connectionconn=null; ResultSetrs=


本例采用access做为实例,所有还有很多要改进的地方。 
请读者自已改进 

package PRodUCt; 
import java.sql.*; 
public class ConnectDB{ 
String strDBDriver="sun.jdbc.odbc.JdbcOdbcDriver"; 
String strConnstr="jdbc:odbc:product"; 
Connection conn=null; 
ResultSet rs=null; 
Statement stmt=null; 
// Statement stmt=null; 
//构造函数 
public ConnectDB(){ 
try{ 
Class.forName(strDBDriver); conn=DriverManager.getConnection(strConnstr); 
stmt=conn.createStatement(); 

catch(Exception e){ 
System.out.println(e); 



public ResultSet execute(String sql){ 
rs=null; 
try{ 

rs=stmt.executeQuery(sql); 

catch(SQLException e){ 
System.out.println(e.getMessage()); 

return rs; 


public Connection getConnection(){ 
return conn; 


public boolean close(){ 
try{ 
if(this.rs!=null){ 
this.rs.close(); 

if(stmt!=null){ 
this.stmt.close(); 

if(conn!=null){ 
this.conn.close(); 

return true; 
}catch(Exception err){ 
return false; 




//======================================= 
package product; 
import java.sql.*; 
public class catalog 

ConnectDB conn=new ConnectDB(); 
String str=null; 
String sql=null; 
ResultSet rs=null; 
String AncestorID,LinkStr; 

public String getCatalog(){ 

str="
Statement:
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