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

    E3p0连接池

    c3p0-config.xml

     

     

    c3p0-config.xml(必须叫这个名字),然后必须放在工程目录的src下面

     

    注意:c3p0里面可以配置多个连接信息,可以给每个配置起个名字,这样可以方便的通过配置名称来切换配置信息。

     

     

     

     Java封装 e3p0:

    publicclass C3P0Util {

        static DataSource cpds=null;

        static{        

              cpds= new ComboPooledDataSource("mysql");

              System.out.println(cpds);

        }

        /**

         * 获得数据库连接

         */

        public static ConnectiongetConnection(){

            try {

                return cpds.getConnection();

            } catch (SQLException e) {

                e.printStackTrace();

                return null;

            }

        }

        

        /**

         * 数据库关闭操作

         */

        public static void close(Connectionconn,PreparedStatement pst,ResultSet rs){

            if(rs!=null){

                try {

                    rs.close();

                } catch (SQLException e) {

                    e.printStackTrace();

                }

            }

            if(pst!=null){

                try {

                    pst.close();

                } catch (SQLException e) {

                   e.printStackTrace();

                }

            }

     

            if(conn!=null){

                try {

                    conn.close();

                } catch (SQLException e) {

                    e.printStackTrace();

                }

            }

        }

    }

  • 相关阅读:
    30个热门的CSS3 Image Hover 脚本
    70个jQuery触摸事件插件 支持手势触摸!
    40个超酷的jQuery动画教程
    45个漂亮且有创意的HTML5网站展示
    40+极具创意的产品展示PSD模板
    25个开始学习HTMLE5的最好的资源
    25个很酷的jQuery倒计时脚本–添加动态计数器!
    45个wordpress自适应插件
    30+WordPress古典风格的主题古典却不失时尚
    为kindeditor上传图片添加水印(PHP版)
  • 原文地址:https://www.cnblogs.com/lyhhary/p/10401672.html
Copyright © 2011-2022 走看看