日期:2014-05-18  浏览次数:20706 次

关于servlet的链表操作,现在只剩下一个将链表存入mysql的函数(saveNode())有毛病了,实在想不出来,大家帮看看,先谢谢了!
Java code
import java.util.Scanner;
import java.io.*; 
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

class Node {
    public int BookStore;                 //图书库存量
    public String BookNo;                //图书编号
    public String BookName;          //图书名称
    public int BookLend;                    //图书上架数量
    public String BookPublishing;//图书出版社
    public Node Next;                       //指向下一个Node对象的对象引用
    
  public Node(){//只有一个节点
      BookNo="000000";
      BookName="书名未初始化";
      BookLend=0;
      BookStore=0;
      BookPublishing="出版社未初始化";
      Next = null;
  }
  public Node(Node eNext,Node t){//不止一个节点
      BookNo=t.BookNo;
      BookName=t.BookName;
      BookLend=t.BookLend;
      BookStore=t.BookStore;
      BookPublishing=t.BookPublishing;
      Next = eNext; 
  }
  public void setData(int eBookStore,int eBookLend,String eBookNo,String eBookName,String eBookPublishing){
      //设置当前结点的值
      BookNo = eBookNo;
      BookName = eBookName;
      BookPublishing = eBookPublishing;
      BookLend = eBookLend;
      BookStore = eBookStore;   
  }

  public Node getData() {//获取当前节点的值
      Node rNode =new Node();
      rNode.BookNo=BookNo;
      rNode.BookName=BookName;
      rNode.BookPublishing=BookPublishing;
      rNode.BookLend=BookLend;
      rNode.BookStore=BookStore;
      rNode.Next=Next;
      return rNode;
  }
  public void setNext(Node dNext){ //设置当前节点的指针
      Next = dNext; 
  } //修改指针
  public Node getNext() {  //获取当前节点的指针
      return Next; 
  } //获得指向的对象引用
}
class LinkList {
private Node firstNode;
private Node headNode=firstNode;
String htm="";
public LinkList()    {        firstNode = null;}//建立空链表    

public String visitAllNode()
{//遍历表中每个结点,并串成一个字符串
Node nextNode = firstNode; 
String s = "<table><tr><td>书号</td><td>书名</td><td>库存量</td><td>上架数量</td><td>出版社</td></tr>";
  while (nextNode != null)  
  { 
      Node number = nextNode.getData();
      s = s +"<tr>";
      s = s +"<td>"+number.BookNo + "</td>";
      s = s +"<td>"+number.BookName + "</td>";
      s = s +"<td>"+number.BookStore + "</td>";
      s = s +"<td>"+number.BookLend + "</td>";
      s = s +"<td>"+number.BookPublishing + "</td></tr>";          
      nextNode = nextNode.getNext();
  }
s+="</table>";
return s;   
}
public String vN()
{//遍历表中每个结点,并串成一个字符串
Node nextNode = firstNode; 
String s = "<table><tr><td>书号</td><td>书名</td><td>库存量</td><td>上架数量</td><td>出版社</td></tr>";
if(nextNode==null){
    s="没有可供删除的结点!";
}
else{
while (nextNode != null)  
{ 
    Node number = nextNode.getData();
    s = s +"<tr>";
    s = s +"<td>"+number.BookNo + "</td>";
    s = s +"<td>"+number.BookName + "</td>";
    s = s +"<td>"+number.BookStore + "</td>";
    s = s +"<td>"+number.BookLend + "</td>";
    s = s +"<td>"+number.BookPublishing + "</td>";
    s = s +"<td><a href=\"DemoLink?menu=1&no="+number.BookNo+"\" target=\"_self\">删 除</a></td></tr>";          
    nextNode = nextNode.getNext();
}
s+="</table>";
}
return s;   
}

public void insertAtEnd(Node tt) //在链表后插入结点
{
    firstNode = new Node(firstNode,tt);
}

public void deleteAtID(String data