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();
}
}
}
}