动态网站制作指南 [  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Java教程
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ Java教程 ]的信息

本月文章推荐
.JDBC基础教程之驱动设置.
.Java新手上路大全(初学者必看).
.让你不苦恼:Java的中文编程配置.
.Applet编程技巧.
.Simply Singleton -- part2 By D.
.如何设置classpath.
.in 运算符.
.用 Validator 简化 Struts 的开发.
.进一步研究字面量.
.CORBA 与Java 的 结 合 使 用.
.使用Java控制UDP协议.
.Java技巧使用管道数据流传送数据.
.自己开发的java中文处理编辑器.
.MVC 构架学习之渐行渐进(一).
.if...else 语句.
.项目开发规范(Java).
.开启Java对代理服务器和HTTP验证.
.初学java应该注意的地方.
.取余运算符 (%).
.JBoss技术支持文档(二).

产品目录/论坛 树形结构的实现

发表日期:2008-1-5 |



原理请参见www.chinaASP.com/sqlbbs中的ASP论坛版精华区
本例采用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)
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" >请选择父类</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>请选择父类</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;
}
}
上一篇:常见的Application Server 人气:782
下一篇:产品介绍:SilverStream eXtend Application Server 人气:579
浏览全部Java的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-8-21 Nucleus v3.33 多国语言版
2008-8-21 HDWiki v4.0 bulid 080821 UTF-8
2008-8-21 明科在线客服系统 v6.0
2008-8-21 KesionCMS v5.0.2 正式版 utf-8
2008-8-21 KesionEshop v5.0.2 正式版 utf-8
2008-8-21 HDWiki v4.0 bulid 080821 GBK
2008-8-21 新文互动酷站展示系统 v1.5
2008-8-21 Punbb v1.2.20 多国语言版
2008-8-21 QQ头像网 beta
2008-8-16 iLaba Player(小喇叭播放器) v2.
2008-8-16 DoubleClickFix 鼠标双击修正工具
2008-8-16 CrystalCPUID 4.15.2.451
2008-8-16 VeryCD 电驴(easyMule) 1.0.4 Bu
2008-8-16 uTorrent 1.8 Build 11813 - Sta
2008-8-16 比特精灵(BitSpirit) v3.3.2.287
2008-8-16 StayInTune音叉 v1.0 破解版
2008-8-16 iChing《周易》汉化补丁 v1.0
2008-8-16 Starmap星空图v1.0汉化破解版
  发表评论
姓 名: 验证码:
内 容:
[ 汉字翻译拼音 ] [ 广告代码 ] [ 符号对照表 ] [ 进制转换 ] [ 经典小工具 ] [ 个税计算 ] [ 汉字简繁转换 ] [ 普通单位换算 ] [ 公制单位换算 ]
[ 生辰老黄历 ] [ 国内电话区号 ] [ 国家代码与域名缩写 ] [ 文字加密解密 ] [ 健康查询 ] [ 万年历 ] [ 手机号码查询 ] [ ip搜索 ] [ Google PR查询 ]
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2008 www.knowsky.com All rights reserved | 网络实名:动态网站制作指南 | 沪ICP备05001343号