1. 程式人生 > >【c3p0】報錯:Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement...

【c3p0】報錯:Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement...

按照書上的指導配置c3p0,但是執行不成功

一開始執行:

資訊: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hgeby99n2wpirj7phm07|69847c5d, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hgeby99n2wpirj7phm07|69847c5d, idleConnectionTestPeriod -> 

然後我重新整理了十幾次,報如下異常了:

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection,  message from server: "Too many connections"

先來看看我配置資料庫連線池的程式碼:

public static Connection getConnection() throws PropertyVetoException, SQLException{//c3p0連線池
		ComboPooledDataSource cpds = new ComboPooledDataSource();
		try {
			cpds.setDriverClass(DriverURL);
		} catch (PropertyVetoException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		cpds.setJdbcUrl(ConURL);
		cpds.setUser(username);
		cpds.setPassword(passwoed);
		cpds.setMaxPoolSize(30);
		cpds.setMinPoolSize(2);
		cpds.setInitialPoolSize(10);
		cpds.setMaxStatements(180);
		return cpds.getConnection();
	}

結合異常宣告:"Too many connections",才知道原來出錯的地方就在這裡:
ComboPooledDataSource cpds = new ComboPooledDataSource();

每次getConnection都會建立一個ComboPooledDataSource類,ComboPooledDataSource是重量級類,建立比較耗費資源,當然會報錯

用單例模式來建立ComboPooledDataSource類即可解決問題:

private static ComboPooledDataSource ds;
	static{
		ds = new ComboPooledDataSource();
		try {
			ds.setDriverClass(DriverURL);
		} catch (PropertyVetoException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		ds.setJdbcUrl(ConURL);
		ds.setUser(username);
		ds.setPassword(passwoed);
		ds.setMaxPoolSize(30);
		ds.setMinPoolSize(2);
		ds.setInitialPoolSize(10);
		ds.setMaxStatements(180);
	}
我是用餓漢式,然後對getConnection方法進行修改:
public static Connection getConnection() throws PropertyVetoException, SQLException{//用連線池
		return ds.getConnection();
	}



相關推薦

c3p0Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement...

按照書上的指導配置c3p0,但是執行不成功 一開始執行: 資訊: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireR

kafkaadvertised.listeners引數的重要性(外部訪問區域網kafka)

嗯,菜雞一個,寫個帖子記錄下解決的一個kafka的問題。 關於kafka的另外兩篇文章! 【kafka】一、kafka框架介紹(生產者篇):https://blog.csdn.net/lsr40/article/details/84029034 【kafka】二、kafka框架介紹(消費

搞了一下午,還是沒有解決,為什麼執行到一半就停在這裡了資訊: Initializing c3p0 pool... com.mchange.v2.c3p0

在進行資料庫資訊的新增和刪除的時候,發現AddServlet和DeleteServlet都不能跳轉到StudentListServlet介面,很奇怪,弄了一天,還是無法解決,並且AddServlet跳轉的時候就停在下面的介面了,請求轉發和重定向好像都沒用了。。。 request.getR

- Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSourc....處理

執行Tomcat 就給我報如下錯誤    原因:連線資料庫的url錯誤 Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 5, acqu

TensorflowValueError: At least two variables have the same name

案例1 問題描述: import tensorflow as tf with tf.Session() as sess: var = tf.Variable(42, name='var') sess.run(tf.global_variables_ini

pythonTypeError: 'builtin_function_or_method' object is unsubscriptable的解決方法

出現這個報錯的原因其實很簡單,就是將小括號'()'寫成了中括號‘[]' 下面來看一個例子: 當一個字典裡面嵌套了字典和列表的時候,再通過字典多層呼叫,將get函式後的小括號寫成了中括號。如下面程式碼第二行: 1.def lookup(data,label,name):

TensorflowCannot interpret feed_dict key as Tensor: The name 'x' refers to an operation, # > no

問題描述: 我嘗試給一個tensor輸入值的時候報錯: Cannot interpret feed_dict key as Tensor: The name 'x' refers to an operation, not a Tensor. Tensor names mu

解決專案啟動停在Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource

錯誤: 今天啟動幾周前的WEB專案的時候就一直卡在如下語句,重啟了幾次Tomcat都是這樣,百度了一下有人說是資料庫的問題,於是嘗試開啟SQL Sever Management Studio嘗試

Ubuntulet notifier = require('update-notifier')({pkg})

npm 不能用報以下錯誤。 /usr/local/lib/node_modules/npm/bin/npm-cli.js:79 let notifier = require('update-notifier')({pkg}) ^^^ SyntaxError: Bloc

Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquire

今天學習spring框架後,自己寫demo時報錯如下,c3p0獲取連線池失敗。 自己在網上搜了很多方法,說的都很模糊。我把自己如何解決的詳細說明一下,希望對大家能有幫助。 上面那些控制檯列印的報錯資訊對解決問題沒有什麼價值,所以用了junit單元測試,檢視junit報錯

spring boot Mybatisorg.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.newhope.interview.dao.UserMapper.add

使用 ase err abstract internal tin mic pre uestc 報錯如下: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): c

Vue.jsElements in iteration expect to have ‘v-bind:key’ directives(vue/require-v-for-key)

寫在開篇,我使用的是webstore編輯器,如果你用的是VScode編輯器,請點選這個連結 說明       一:我沒有驗證過上述VScode版方案是否能解決此問題       二:寫在開篇的原因是小編在解決這個問題的過程實在曲折,算是給大家排個雷吧 正文開始

SSM及解決

  spring mvc mybatis 整合錯誤1 (放置事務註解的位置錯誤)(表現:直接訪問.jsp,.html報錯,寫一個測試類,測試mapper,報錯) org.springframework.beans.factory.parsing.BeanDefinit

pythonModuleNotFoundError: No module named ‘xxx’

在命令列輸入python [檔名].py,報錯ModuleNotFoundError: No module named ‘xxx’檢查一下test_mysql_orm檔案/資料夾是否在命令行當前執行的目

ydc_coding專案地址www.ydc-coding.com

專欄達人 授予成功建立個人部落格專欄

依賴ConstraintLayoutCould not find com.android.support.constraint:constraint-layout:1.0.0-beta5

ConstraintLayout是Android Studio 2.2中主要的新增功能之一,方便開發者使用圖形化介面來完成UI佈局,減少佈局巢狀。更多的使用方法,可以參考這篇文章:ConstraintLayout完全解析 在進行佈局轉換時,我們需要新增依賴: compi

Android開發android studio Failed to resolve: com.android.support.constraint:constraint-layout:1.0.

情景:在build.gradle檔案新增下面程式碼 compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4' 點選“Sync now”後報錯: Failed to resolve:co

JDBCjava.lang.ClassNotFoundException: com.mysql.jdbc.Driver

    記錄一個小問題,折騰了兩個小時,在java工程下面,寫了程式,放到Web專案下面就是報錯,排查發現是資料庫連線這裡有報錯,報錯內容如下: java.lang.ClassNotFoundEx

The declared package "com.cas" does not match the expected package "main.java.com.cas"

1 、說明 環境說明:2018eclipse + jdk1.8 + tomcat 8 經常搗騰開發環境,昨天還好好的,今天來了,突然發現 所有的類都報錯,這可如何是好,措手不及的感覺有木有0.0,

解決com.mchange.v2.c3p0.impl.NewProxyResultSet.getNString(Ljava/lang/String;)Ljava/lang/String;]

前言:       在寫一個專案的時候,使用Spring+SpringMVC+Mybatis框架,資料庫連線池使用c3p0<0.9.1.2版本>。在連線SqlServer時,一切都正常。當時當查詢出來的結果中含有欄位型別為nvarchar時,報出了以下錯誤: 嚴