通过sql-lite保存数据库属性

时间:2013-04-20 09:12:05

标签: java database sqlite xml-formatting

在我的程序中,我为用户提供了设计自己的数据库的工具。我成功地获得了表格及其值保存在我的班级对象中。

现在我想将它保存在sql lite中/创建该数据库的输出xml文件。

public class Table
{
private ArrayList<Column> columns;
private String NAME;
private static int count=0;
public Table() 
{
    columns = new ArrayList<Column>();
    NAME=new String();

    this.NAME="Table"+count;
    count++;
}

public void AddColumn(Column column)
{
    for(Column c: columns)
    {
       if(c.getname().equals(column.getname())){return;}
    }

    columns.add(column);

}

public void SaveToFile() throws IOException
{


    FileWriter fw = new FileWriter("C:/Users/Ashad/Desktop/text.txt", true);
    BufferedWriter bw = new BufferedWriter(fw);
     bw.write("\r\n");
    bw.write(this.NAME);
     bw.write("\r\n");

for(Column c: columns)
{
 bw.write("\r\n");
        bw.write(c.getname()+"  ");

        bw.write(c.getdatatype()+"  ");


 if(c.getPK()== true)
 {
        bw.write("true"+"  ");

 }    
    else
    {   bw.write("false"+"  ");

    }
if(c.getNN()== true)
{
    bw.write("true"+"   ");

}     
else
    {bw.write("false"+"  "); } 



}
bw.close();
}

public boolean DeleteColumn(String name)
{
    for (Column c : columns)
    {
        if (c.getname().equals(name)) {return columns.remove(c);}
    }
    return false;
}

public void viewColumns()
{
      System.out.append(NAME+"  ");

    for(Column c: columns)
  {
      System.out.append("\n");
      System.out.append(c.getname()+"  ");

      System.out.append( c.getdatatype()+"  ");

if(c.getPK()== true)
{
    System.out.print(true);
}     
else
    System.out.print(false);  
  }
}

public String getNAME() {

    return NAME;
}

}



public class Column
{
private String name;
   private String dataType;
  private boolean PK;
  private boolean NN;


  public Column()
 {
 String name=new String();
 String dataType=new String();  
 boolean PK=false;
 boolean NN=false;
 }  
 public String getname(){return name;}
 public String getdatatype(){return dataType;}
 public boolean getPK(){return PK;}
 public boolean getNN(){return NN;}

 public void setname(String n){name=n;}
 public void setdatatype(Object object){dataType=(String) object;}
 public void setPK(boolean p){PK=p;}
 public void setNN(boolean n){NN=n;}


}

0 个答案:

没有答案