?? createtable.java
字號:
import javax.xml.parsers.*;
import java.io.*;
import org.xml.sax.*;
import org.w3c.dom.*;
import java.awt.*;
class cols
{
String colname=null;
cols next=null;
cols(String name)
{
colname=name;
}
}
public class Createtable
{
String tablename;
cols colhead=new cols("head"),c1=colhead,c2;
word list=null;
String temp; //詞語的內容
int wordtype=-1; //詞語的類型
public void createtable(word wordlist,TextArea Check,database db)
{
System.out.println("!!!!!!!!!!!!!建立表!!!!!!!!!!!!!!!!");
list=wordlist;
list=list.next;
int colnum=0;
/**************************************/
if( list==null )
{
Check.append("命令沒有完結\n");
return;
}
/**************************************/
if( list.type!=1 )
{
Check.append("表名"+list.name+"錯誤\n");
return;
}
/*已經通過表名驗證*/
tablename=list.name; //獲得表名
list=list.next;
/**************************************/
if( list==null )
{
Check.append("命令沒有完結\n");
return;
}
/**************************************/
if(!list.name.equals("("))
{
Check.append("缺少(\n");
return;
}
list=list.next;
/**************************************/
if( list==null )
{
Check.append("命令沒有完結\n");
return;
}
/**************************************/
if(list.type!=1)
{
Check.append("列名錯誤\n");
return;
}
while( (list.name!=")") )
{
if(list.type!=1)
{
Check.append("列名錯誤\n");
return;
}
temp=list.name;
c2=new cols(temp);c1.next=c2;c1=c2;c2=c2.next;
colnum++; //列的數目
list=list.next;
/**************************************/
if( list==null )
{
Check.append("命令沒有完結\n");
return;
}
/**************************************/
if(list.name.equals(")"))
{
break;
}
if( (list.name==";") || (list.next==null) ) //若沒有讀到)直接讀到了;或者命令結束則報錯
{
Check.append("缺少)\n");
return;
}
if(!list.name.equals(","))
{
Check.append("缺少,\n");
return;
}
list=list.next;
}
/*已經讀取到)*/
list=list.next;
/**************************************/
if( list==null )
{
Check.append("命令沒有完結\n");
return;
}
/**************************************/
if( (list.name.equals(";")) && (list.next==null) )
{
//命令結束,可以建立表
System.out.println(tablename);
c1=colhead;
/*******************************************/
while(c1!=null)
{
System.out.println("colname: "+c1.colname);
c1=c1.next;
}
/********************************************/
}
else
{
//命令;結束后還有字符,說明錯誤
Check.append(";后面還有字符或者)后面沒有;\n");
return;
}
/*#######################建立xml table############################*/
try
{
if(db==null)
{
Check.append("沒有創建數據庫\n");
return;
}
Document document=db.document;
Node root=document.getDocumentElement();//root是根元素
NodeList nodes=root.getChildNodes();
for(int i=0;i<nodes.getLength();i++)
{
if(nodes.item(i).getAttributes().item(0).getNodeValue().equals(tablename))
{
Check.append("你已經建立了相同的表,請不要重復建立\n");
return;
}
}
Element temp_element=(Element)document.createElement("table"),ele;
temp_element.setAttribute("name",tablename);
temp_element.setAttribute("colnum",String.valueOf(colnum));
root.appendChild(temp_element);
ele=(Element)document.createElement("titles"); //ele是列名的一張表,因為空表要保存列名
temp_element.appendChild(ele);
c1=colhead.next; //準備把新建的所有列放到第一個(titles中作為列名的一張表)
while(c1!=null)
{
ele.appendChild(document.createElement(c1.colname));
c1=c1.next;
}
Show sh=new Show();
sh.show(root);
//show(root);
Check.append("你已經成功建立了"+tablename+"表\n");
}catch(Exception ee){System.out.println(ee);}
}
void show1(Node eee)
{
System.out.print(eee.getNodeName()+" :");
if(eee.hasAttributes())
{
NamedNodeMap atts=eee.getAttributes();
for(int j=0;j<atts.getLength();j++)
{
Node att=atts.item(j);
System.out.print(" +-- "+att.getNodeName()+"/"+att.getNodeValue());
}
}
System.out.println(" ");
if(eee.hasChildNodes())
{
NodeList nodes=eee.getChildNodes();
for(int i=0;i<nodes.getLength();i++)
{
show1(nodes.item(i));
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -