zoukankan      html  css  js  c++  java
  • Last packet sent to the server was 0 ms ago.

    Last packet sent to the server was 0 ms ago.
    com.alibaba.druid.pool.GetConnectionTimeoutException: loopWaitCount 0, wait millis 60552, active 0



    使用droid出现上述问题
    后经分析发现
    1:用户名密码不正确,也报这个错
    2:用户权限不正确也报这个错
    3:访问地址不正确也报这个错  ?????
    4:重新设置地址,重新加正确的权限,正确的地址
      常用一样很重要改写的droidUtils工具类
      温大侠讲,可以是线程问题..
      //-----------------------------------
    package com;

    import java.io.BufferedInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.Properties;

    import javax.sql.DataSource;

    import com.alibaba.druid.pool.DruidDataSourceFactory;

    public class DruidUtilsPro {

        public static String confile = "druid.properties";
        public static Properties p = null;
        private static DataSource dataSource = null;
        //将一个对象和线程绑定
            private static ThreadLocal<Connection> connLocal =
                                new ThreadLocal<Connection>();
            
        static {
            p = new Properties();
            InputStream inputStream = null;
            try {
                // java应用
                confile = DruidUtilsPro.class.getClassLoader().getResource("")
                        .getPath()
                        + confile;
                //System.out.println(confile);
                File file = new File(confile);
                inputStream = new BufferedInputStream(new FileInputStream(file));
                p.load(inputStream);
                initDataSource();//初始化连接池
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    if (inputStream != null) {
                        inputStream.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        /**
         * 根据类型获取数据源
         *
         * @param sourceType
         *            数据源类型
         * @return druid或者dbcp数据源
         * @throws Exception
         *             the exception
         */
        public static final void initDataSource()
                 {
            //DataSource dataSource = null;

            try {
                dataSource = DruidDataSourceFactory.createDataSource(p);
                //dataSource =  dataSource1;
            } catch (Exception e) {
                //e.printStackTrace();
                throw new RuntimeException(e);
            }
            
        }
        
        
        public static Connection getConnection(){
            Connection conn = connLocal.get();
            try {
                if(conn == null || conn.isClosed()){//如果没有,或已关闭
                    conn = dataSource.getConnection();//获取新的connection
                    connLocal.set(conn);
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return conn;

        }
        
        public static void close(Connection co){
            //获取和当前线程相关的connection
            Connection conn = connLocal.get();
            //清除和线程绑定的conn
            connLocal.set(null);//为下一次调用getConnection要新建
            try {
                if(conn != null){
                    conn.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }    
        }
        
        public static void close(Statement stmt){
            if(stmt != null){
                try {
                    stmt.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }    
        }    
        
        public static void close(ResultSet rs){
            if(rs != null){
                try {
                    rs.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }    
        }        
    }

  • 相关阅读:
    continue语句及小案例
    break语句和break版猜数字游戏
    python 用while语句打印99乘法表
    python2中引入python3中print函数的语法的语句
    【猜数字 小游戏】
    【while循环】
    代码块和缩进
    使用vs2015编写c语言的方法
    This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details
    矩阵相乘法则和技巧
  • 原文地址:https://www.cnblogs.com/kaka100/p/3405898.html
Copyright © 2011-2022 走看看