zoukankan      html  css  js  c++  java
  • 后台调用数据库

    在类中:

    import org.springframework.jdbc.core.JdbcTemplate;

    public JdbcTemplate jdbcTemplate;

     

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {

    this.jdbcTemplate = jdbcTemplate;

    }

    在方法中:

    Connection conn = null;

    Statement stm = null;

    try {

    conn = jdbcTemplate.getDataSource().getConnection();

    conn.setAutoCommit(false);

    stm = conn.createStatement();

    String updateSql = "";

    stm.executeUpdate(updateSql);//修改、删除

    conn.commit();

    }catch (Exception e) {

    LogUtil.error(e.getMessage(),e);

    try {

    conn.rollback();

    } catch (SQLException e1) {

    LogUtil.error(e1.getMessage(),e1);

    }

    } finally {

    try {

    if (stm != null) {

    stm.close();

    }

    if (conn != null) {

    conn.close();

    }

    } catch (Exception e) {

    LogUtil.error(e.getMessage(),e);

    }

    }

    查询:

    StringBuffer sql = new StringBuffer();

    sql.append(" SELECT ");

    List<CLS_VO_Obj>objList = jdbcTemplate.queryForList(sql.toString(), CLS_VO_Obj.class);

  • 相关阅读:
    暑假自学(19)
    暑假自学(18)
    暑假自学(17)
    暑假自学(16)
    暑假自学(15)
    rsync简介
    10.Go语言-面向对象简单了解
    dp 数字三角形
    P1359租用游艇(dp+dfs)
    油田问题 bfs
  • 原文地址:https://www.cnblogs.com/7q4w1e/p/9592441.html
Copyright © 2011-2022 走看看