1
回答
mysql 连接数过多 包错:"Host '192.168.10.15' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'"
终于搞明白,存储TCO原来是这样算的>>>   

1.用阿里的连接池  配置如下:

<bean id="Template_DataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close"> 
   <property name="url" value="jdbc:mysql://10.96.9.105/smg?useUnicode=true&amp;characterEncoding=utf-8&amp;autoReconnect=true&amp;zeroDateTimeBehavior=convertToNull" />
   <property name="username" value="root" />
   <property name="password" value="" />
   <property name="filters" value="stat" />
   <property name="maxActive" value="20" />
   <property name="initialSize" value="1" />
   <property name="maxWait" value="60000" />
   <property name="minIdle" value="1" />
   <property name="timeBetweenEvictionRunsMillis" value="60000" />
   <property name="minEvictableIdleTimeMillis" value="300000" />
   <property name="validationQuery" value="SELECT 'x'" />
   <property name="testWhileIdle" value="true" />
   <property name="testOnBorrow" value="false" />
   <property name="testOnReturn" value="false" />
   <property name="poolPreparedStatements" value="true" />
   <property name="maxPoolPreparedStatementPerConnectionSize" value="20" />
    </bean>


2.spring 对数据库操作:

private JdbcTemplate getJdbcTemplate() {
JdbcTemplate jt = (JdbcTemplate) this.getApplicationContext().getBean("Template_JdbcTemplate");
return jt;
}


public boolean update(String sql) {
int i = this.getJdbcTemplate().update(sql);
return i > 0;
}

场景:该应用定时的更新数据库表(每20min) 请问问题出在哪里?




举报
wangxi得
发帖于3年前 1回/646阅
顶部