程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> JSP編程 >> 關於JSP >> 產品目錄/論壇 樹形結構的實現-JSP教程,面向對象/設計

產品目錄/論壇 樹形結構的實現-JSP教程,面向對象/設計

編輯:關於JSP

本例采用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="<select name="FatherID" class="p9"> "+
"<option value="-1" selected>請選擇父類</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)

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved