作者QQ:1095737364 QQ群:123300273 歡迎加入!
execute方法:可以用於執行任何SQL語句,一般用於執行DDL語句;
update方法及batchUpdate方法:update方法用於執行新增、修改、刪除等語句;
batchUpdate方法用於執行批處理相關語句;
query方法及queryForXXX方法:用於執行查詢相關語句;
call方法:用於執行存儲過程、函數相關語句。
1.添加一條語句:
String sql = "INSERT INTO emailconfig ( smtp , smtpport,) VALUES('"+emailConf.getSmtp()+"','"+emailConf.getSmtpport()+"')";//使用拼接的方式傳遞參數 this.jdbcTemplate.update(sql);
2.修改一條語句:
String sql="update temporary_email_conf set IsProcess=1 where emailName=? AND IsProcess=0"; this.jdbcTemplate.update(sql,new Object[]{emailConf.getSername()});//使用Object 數組來傳遞參數
3.刪除一條語句:
String sql="delete FROM emailconfig WHERE emailsuffix ='"+emailConf.getEmailsuffix()+"'"
this.jdbcTemplate.update(sql);
4.查詢:
String sql="select * from temporary_email_conf where (IsSuccess=0 OR pop3='' OR pop3 is null OR imap='' OR imap is null) and IsProcess=0 "; return this.jdbcTemplate.query(sql,new BeanPropertyRowMapper<TemporaryEmailConf>(TemporaryEmailConf.class));//查詢一個list的集合對象 String sql="select * from temporary_email_conf where emailName=? and IsProcess=0 "; return this.jdbcTemplate.queryForObject(sql,new Object[]{emailName},new BeanPropertyRowMapper<TemporaryEmailConf>(TemporaryEmailConf.class));//查詢單個對象 String sql="select count(*) from emailconfig WHERE emailsuffix='"+emailConf.getEmailsuffix()+"'"; return jdbcTemplate.queryForInt(sql);//查詢整形的數字