JDBC为什么查询语句使用StringBuilder
JDBC为什么查询语句使用StringBuilder,
StringBuilder sb=new StringBuilder();
sb.append("select * from imooc_goddess ");
sb.append(" where user_name like ? and mobile like ? and email like ?");
PreparedStatement ptmt=conn.prepareStatement(sb.toString());
必须使用StringBuilder吗?可不可以直接像增删改类似的
String sql="" +
"insert into imooc_goddess" +
"(user_name,sex,age,birthday,email,mobile," +
"create_user,create_date,update_user,update_date,isdel)" +
"values(" +
"?,?,?,?,?,?,?,current_date(),?,current_date(),?)";
PreparedStatement ptmt=conn.prepareStatement(sql);
写成
String sql="" +
" select * from imooc_goddess " +
" where user_name like ? and mobile like ? and email like ? ";
PreparedStatement ptmt=conn.prepareStatement(sql);
有什么讲究吗?