国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

產(chǎn)品目錄/論壇 樹(shù)形結(jié)構(gòu)的實(shí)現(xiàn)

2019-11-18 15:14:20
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

原理請(qǐng)參見(jiàn)www.chinaasp.com/sqlbbs中的ASP論壇版精華區(qū)
本例采用access做為實(shí)例,所有還有很多要改進(jìn)的地方。
請(qǐng)讀者自已改進(jìn)

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;
//構(gòu)造函數(shù)
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="<select name="FatherID" class="p9"> "+
"<option value="-1" selected>請(qǐng)選擇父類(lèi)</option> ";
String sql=null;
sql="select * from catalog order by AncestorID,Linkstr";
ResultSet rs=conn.execute(sql);
try{
while (rs.next()) {
str=str+"<option value="+rs.getString("Productid")+">";
int nbspCount=rs.getString("LinkStr").length()-1;
for(int i=0;i<nbspCount;i++){
str=str+" ";
}
if(nbspCount>0)
str=str+"┠"+rs.getString("title")+"</option> ";
else
str=str+rs.getString("title")+"</option> ";

}
str=str+"</select>";
rs.close();
}
catch(SQLException e){
System.out.println(e.getMessage());
}
return str;
}
public void setCatalog(String CatalogName,String FatherID){
int ChildNum=0;
if(FatherID.compareTo("-1")!=0){
sql="select AncestorID,ChildNum,linkstr from catalog where productid="+FatherID;
//out.println(sql);
try{
rs=conn.execute(sql);
if(rs.next()){
AncestorID=rs.getString("AncestorID");
ChildNum=rs.getInt("ChildNum");
LinkStr=rs.getString("linkstr");
}
else{
AncestorID="";
LinkStr="1";
ChildNum=0;
}
LinkStr=LinkStr+(ChildNum+1);
//out.println(AncestorID+":"+LinkStr+":"+ChildNum);
sql="insert into catalog(title,fatherID,AncestorID,LinkStr) values(′′"+CatalogName+"′′,′′"+FatherID+"′′,′′"+AncestorID+"′′,′′"+LinkStr+"′′)";
//out.println(sql);
conn.execute(sql);
sql="update catalog set childNum="+(ChildNum+1)+" where productID="+FatherID;
//out.println("<br>"+sql);
conn.execute(sql);
}catch(Exception e){
System.out.println(e);
}

}else{
sql="insert into catalog(title,fatherID,LinkStr) values(′′"+CatalogName+"′′,′′"+FatherID+"′′,′′1′′)";
//out.println(sql);
try{
conn.execute(sql);
sql="select top 1 productID from catalog order by productID desc ";
rs=conn.execute(sql);
if(rs.next()){
AncestorID=rs.getString("productID");
}
else{
AncestorID="";
}
rs.close();
sql="update catalog set AncestorID=′′"+AncestorID+"′′ where productID="+AncestorID;
//out.println(sql);
conn.execute(sql);
}catch(Exception e){
System.out.println(e);

}

}//end if

if(rs!=null){
try{
rs.close();
}catch(Exception e){
System.out.println(e);
}
}

}

public void deleteCatalog(String FatherID){
int tempData=0;
sql="select fatherID,linkstr,AncestorID from catalog where productID="+FatherID;
rs=conn.execute(sql);
try{
if(rs.next()){
tempData=rs.getInt("fatherID");
LinkStr=rs.getString("linkstr");
AncestorID=rs.getString("AncestorID");
}

try{rs.close();}
catch(Exception e){
System.out.println(e);
}
sql="delete from catalog where ProductID="+FatherID;
// out.println(sql);
try{
conn.execute(sql);
}catch(Exception e){
System.out.println(e);
}
sql="delete from catalog where linkstr like ′′"+LinkStr+"%′′ and AncestorID="+AncestorID;
//out.println(sql);
try{
conn.execute(sql);
}catch(Exception e){
System.out.println(e);
}
sql="update catalog set ChildNum=ChildNum-1 where productID="+tempData;
//out.println(sql);
try{
conn.execute(sql);
}catch(Exception e){
System.out.println(e);
}
}catch(Exception e){
System.out.println(e);
}
} //end public

public void updateCatalog(int id){

}

public String getCatalog(int id){

str="<select name="FatherID" class="p9"> "+
"<option value="-1" >請(qǐng)選擇父類(lèi)</option> ";
String sql=null;
sql="select * from catalog order by AncestorID,Linkstr";
ResultSet rs=conn.execute(sql);
try{
while (rs.next()) {
int ProductID=rs.getInt("productID");
if (ProductID==id) {
str=str+"<option value="+ProductID+" selected>";
}
else{
str=str+"<option value="+ProductID+">";
}
int nbspCount=rs.getString("LinkStr").length()-1;
for(int i=0;i<nbspCount;i++){
str=str+" ";
}
if(nbspCount>0)
str=str+"┠"+rs.getString("title")+"</option> ";
else
str=str+rs.getString("title")+"</option> ";

}
str=str+"</select>";
rs.close();
}
catch(SQLException e){
System.out.println(e.getMessage());
}
return str;
}

public String getCatalogList(){

str="<select name="FatherID" class="p9" size="20" onClick="MM_jumpMenu(′′parent.mainFrame′′,this,0)"> "+
"<option value="-1" selected>請(qǐng)選擇父類(lèi)</option> ";
String sql=null;
sql="select * from catalog order by AncestorID,Linkstr";
ResultSet rs=conn.execute(sql);
try{
while (rs.next()) {
str=str+"<option value="+rs.getString("Productid")+">";
int nbspCount=rs.getString("LinkStr").length()-1;
for(int i=0;i<nbspCount;i++){
str=str+" ";
}
if(nbspCount>0)
str=str+"┠"+rs.getString("title").trim()+"</option> ";
else
str=str+rs.getString("title")+"</option> ";

}
str=str+"</select>";
rs.close();
}
catch(SQLException e){
System.out.println(e.getMessage());
}
return str;
}
}

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 怀化市| 都匀市| 福贡县| 涟源市| 东莞市| 巩留县| 那坡县| 成安县| 岳阳县| 凤翔县| 金华市| 南充市| 临江市| 江源县| 抚顺市| 象山县| 包头市| 武强县| 措勤县| 齐河县| 镇赉县| 南充市| 台东县| 华宁县| 顺平县| 儋州市| 府谷县| 闽清县| 龙门县| 锦屏县| 大兴区| 梁平县| 腾冲县| 梁河县| 工布江达县| 娱乐| 江津市| 镇宁| 明溪县| 甘洛县| 蒲城县|