• JdbcTemplate 方法使用


    作者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);//查询整形的数字

      

    
    
    
  • 相关阅读:
    CDQ分治
    2-sat
    整体二分
    apache性能优化
    apache反向代理出现502调整
    hadoop学习笔记肆--元数据管理机制
    ssh 免密码登录配置,及其原理
    extjs 中的一些鲜为人知的属性(深渊巨坑)
    hadoop学习笔记叁--简单应用
    hadoop学习笔记贰 --HDFS及YARN的启动
  • 原文地址:https://www.cnblogs.com/yysbolg/p/6699484.html
Copyright © 2020-2023  润新知