qq_不囧_0
2018-02-22 18:02
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);
有什么讲究吗?
试着写了一下,两种都对的。
String sql="" +
" select * from imooc_goddess" +
" where user_name like ? and mobile like ? and email like ? ";
System.out.println("sql:"+sql);
PreparedStatement ptmt=conn.prepareStatement(sql);
JDBC之 “ 对岸的女孩看过来”
99327 学习 · 856 问题
相似问题