zoukankan      html  css  js  c++  java
  • jdbc操作

    public class Activityjdbc {
        
        private DataSource dataSource;
        protected static final Logger logger = LoggerFactory.getLogger(Activityjdbc.class);
    
        /**
         * 插入
         */
        public void insert() {
            String sql ="插入sql语句";
            Connection  conn = null;
            Statement state =null;
            try {
                conn = dataSource.getConnection();
                 state = conn.createStatement();
                state.executeUpdate(sql);
                conn.commit();//提交(增,删,改)
            } catch (SQLException e) {
                JdbcUtil.rollbackConnection(conn);
                logger.info(e.getMessage(), e);
            }finally{
                JdbcUtil.closeStatement(state);
                JdbcUtil.closeConnection(conn);
            }
        }
    
        /**
         * 查询
         */
        public void QueryHdIndex() {
            String sql = "查询语句";int a = 0;
            Connection  conn = null;
            Statement state =null;
            ResultSet rs=null;
            try {
                conn = dataSource.getConnection();
                 state = conn.createStatement();
                 rs = state.executeQuery(sql);
                while (rs.next()) {
                    a = rs.getInt(0);
                }
            } catch (SQLException e) {
                JdbcUtil.rollbackConnection(conn);
                logger.info(e.getMessage(), e);
            }finally{
                JdbcUtil.closeResultSet(rs);
                JdbcUtil.closeStatement(state);
                JdbcUtil.closeConnection(conn);
            }
           
        }
    public DataSource getDataSource() {
            return dataSource;
        }
        public void setDataSource(DataSource dataSource) {
            this.dataSource = dataSource;
        }
        
    }
  • 相关阅读:
    babel6的babel-plugin-add-module-exports插件
    babel ---- presets字段设定转码规则
    Babel6.x的安装过程
    npm
    JavaScript的数组
    JavaScript的数据类型
    JavaScript
    数据类型详解
    jsp笔记总结
    Servlet学习总结
  • 原文地址:https://www.cnblogs.com/mcahkf/p/4766388.html
Copyright © 2011-2022 走看看