为了避免打关键字出错,特意写的工具类
/**
* sql字符串追加器
* @author Sam
*
*/
public class sqlBuilder
{
private StringBuilder builder;
private final String TAB = " ";
public sqlBuilder()
{
builder = new StringBuilder();
}
public sqlBuilder addsql(String value)
{
builder.append(TAB+value+TAB);
return this;
}
/**
* 添加左括号
* @return
*/
public sqlBuilder addleftBracket()
{
builder.append("(");
return this;
}
/**
* 添加integer类型
* @return
*/
public sqlBuilder addInt()
{
this.addsql("integer");
return this;
}
/**
* 添加text类型
* @return
*/
public sqlBuilder addText()
{
this.addsql("text");
return this;
}
/**
* 追加varchar
* @param len 长度
* @return
*/
public sqlBuilder addVarchar(int len)
{
this.addsql("varchar").addleftBracket().add(len).addRightBracket();
return this;
}
/**
* 添加右括号
* @return
*/
public sqlBuilder addRightBracket()
{
builder.append(")");
return this;
}
/**
* 添加逗号
* @return
*/
public sqlBuilder addComma()
{
builder.append(",");
return this;
}
/**
* 追加not null
* @return
*/
public sqlBuilder addNotNull()
{
this.addsql("not null");
return this;
}
public sqlBuilder addNull()
{
this.addsql("null");
return this;
}
public sqlBuilder addPrimarykey()
{
this.addsql("primary key");
return this;
}
public sqlBuilder add(Object value)
{
builder.append(value);
return this;
}
/**
* 添加自增长字段
* @return
*/
public sqlBuilder addautoincrement()
{
this.addsql("autoincrement");
return this;
}
/**
* "create table if not exists"
* @return
*/
public sqlBuilder addCreatetableIfNotExists()
{
this.addsql("create table if not exists");
return this;
}
/**
* 添加属性字段
* @param element
* @return
*/
public sqlBuilder addElement(String element)
{
this.addsql(element);
return this;
}
public String toString()
{
return builder.toString();
}
}
--------------------------------------------------------------------------------------------------------------------------------------
public static voID main(String[] args)
{
sqlBuilder builder = new sqlBuilder();
builder.addCreatetableIfNotExists().addElement("student");
builder.addleftBracket();
builder.addElement("ID").addInt().addNotNull().addPrimarykey().addautoincrement().addComma();
builder.addElement("age").addInt().addNull().addComma();
builder.addElement("name").addVarchar(25).addNull().addComma();
builder.addElement("info").addText().addNull();
builder.addRightBracket();
System.out.println(builder);
}
---------------------------------------------------------------------------------------------
总结以上是内存溢出为你收集整理的SQLite数据库拼写工具类全部内容,希望文章能够帮你解决SQLite数据库拼写工具类所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)