一、使用String.format方法html
java.util.Date d=new java.util.Date();
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String s=df.format(d);java
String sql=String.format("insert into FirstLevelTitle values(%d,'%s','%s','%s')",13,"科技","管理員",s);sql
%s表示字符串類型,%d表示整數類型(十進制)post
其餘類型表示方式,請參考:spa
http://blog.csdn.net/lonely_fireworks/article/details/7962171.net
http://www.cnblogs.com/fsjohnhuang/p/4094777.htmlorm
二、使用MessageFormat.format方法htm
String sql=MessageFormat.format("insert into FirstLevelTitle values({0},''{1}'',''{2}'',''{3}'')",14,"科技","管理員",s);blog
注意:單引號要用兩個單引號才能表示出來字符串
進一步的使用,請參考:
http://blog.csdn.net/zhiweianran/article/details/8666992