Spring4.1 use C3P0 to load the configuration file to connect to the database, Access denied for user ' root ' @ ' localhost ' ERROR!

Source: Internet
Author: User

db.properties
jdbc.user=root jdbc.password=admin Jdbc.driverclass=com.mysql.jdbc.driver Jdbc.jdbcurl=jdbc\:mysql\:///spring4 jdbc.initialpoolsize=5 jdbc.maxpoolsize=10
in Spring.xml
<context:property-placeholder location= "classpath:db.properties"/><!--configuring C3P0 data Sources --<bean id= "DataSource" class= "Com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method= "Close" ><property name= "user" value= "${jdbc.user}" ></property><property name= "password" value= "${jdbc.password}" ></property><property name= "Driverclass" value= "${jdbc.driverclass}" ></property><property name= "Jdbcurl" value= "${jdbc.jdbcurl}" ></property><property name= "initialpoolsize" value= "${jdbc.initialpoolsize}" ></property><property name= "maxpoolsize" value= "${jdbc.maxpoolsize}" ></property></bean>
Test Code:
public class Test {  public static void Main (string[] args) {   applicationcontext ctx = new Classpathxmlapplicationcontext (" Beans.xml ");   DataSource DataSource = (DataSource) Ctx.getbean (" DataSource ");   System.out.println (dataSource); &NBSP;} }
if in the db.properties file, the user name or password after the existence of a space, you will be reported the following error, visible c3p0 to the configuration file read very human, a little attention on the problem, it is difficult to find out.
January 30, 2015 10:45:38 am Com.mchange.v2.resourcepool.basicresourcepool$scatteredacquiretask Run
Warning: com.mchange.v2.resourcepool.basicresourcepool$[email protected]--acquisition attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition at tempts (30). Last acquisition attempt exception:
Java.sql.SQLException:Access denied for user ' root ' @ ' localhost ' (using Password:yes)
At Com.mysql.jdbc.SQLError.createSQLException (sqlerror.java:1073)
At Com.mysql.jdbc.MysqlIO.checkErrorPacket (mysqlio.java:3593)
At Com.mysql.jdbc.MysqlIO.checkErrorPacket (mysqlio.java:3525)
At Com.mysql.jdbc.MysqlIO.checkErrorPacket (mysqlio.java:931)
At com.mysql.jdbc.MysqlIO.secureAuth411 (mysqlio.java:4031)
At Com.mysql.jdbc.MysqlIO.doHandshake (mysqlio.java:1296)
At Com.mysql.jdbc.ConnectionImpl.coreConnect (connectionimpl.java:2338)
At Com.mysql.jdbc.ConnectionImpl.connectOneTryOnly (connectionimpl.java:2371)
At Com.mysql.jdbc.ConnectionImpl.createNewIO (connectionimpl.java:2163)
At Com.mysql.jdbc.connectionimpl.<init> (connectionimpl.java:794)
At Com.mysql.jdbc.jdbc4connection.<init> (jdbc4connection.java:47)
At Sun.reflect.GeneratedConstructorAccessor7.newInstance (Unknown Source)
At Sun.reflect.DelegatingConstructorAccessorImpl.newInstance (delegatingconstructoraccessorimpl.java:45)
At Java.lang.reflect.Constructor.newInstance (constructor.java:408)
At Com.mysql.jdbc.Util.handleNewInstance (util.java:407)
At Com.mysql.jdbc.ConnectionImpl.getInstance (connectionimpl.java:378)
At Com.mysql.jdbc.NonRegisteringDriver.connect (nonregisteringdriver.java:305)
At Com.mchange.v2.c3p0.DriverManagerDataSource.getConnection (drivermanagerdatasource.java:146)
At Com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection (Wrapperconnectionpooldatasource.java : 195)
At Com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection (Wrapperconnectionpooldatasource.java : 184)
At Com.mchange.v2.c3p0.impl.c3p0pooledconnectionpool$1pooledconnectionresourcepoolmanager.acquireresource ( C3P0POOLEDCONNECTIONPOOL.JAVA:200)
At Com.mchange.v2.resourcepool.BasicResourcePool.doAcquire (basicresourcepool.java:1086)
At Com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess ( basicresourcepool.java:1073)
At com.mchange.v2.resourcepool.basicresourcepool.access$800 (basicresourcepool.java:44)
At Com.mchange.v2.resourcepool.basicresourcepool$scatteredacquiretask.run (basicresourcepool.java:1810)
At Com.mchange.v2.async.threadpoolasynchronousrunner$poolthread.run (threadpoolasynchronousrunner.java:648)
Configure the correct output results:
Com.mchange.v2.c3p0.ComboPooledDataSource [Acquireincrement, 3, acquireretryattempts, Acquireretrydelay , Autocommitonclose, False, automatictesttable, NULL, Breakafteracquirefailure, FALSE, Checkoutt Imeout, 0, connectioncustomizerclassname, NULL, Connectiontesterclassname Com.mchange.v2.c3p0.impl.DefaultConnectionTester, DataSourceName-1hgery997fqt554114cyr|4de5031f, Debugunreturnedconnectionstacktraces, False, description, NULL, Driverclass-Com.mysql.jdbc.Driver, Factoryclasslocation, NULL, Forceignoreunresolvedtransactions, FALSE, Identitytoken 1hgery997fqt554114cyr|4de5031f, Idleconnectiontestperiod-0, Initialpoolsize-5, Jdbcurl-jdbc:mysql:/// Spring4, Maxadministrativetasktime-0, maxconnectionage-0, MaxIdleTime-a 0, maxidletimeexcessconnections- > 0, maxpoolsize, maxstatements, 0, maxstatementsperconnection, 0, Minpoolsize, 3, NuMhelperthreads-3, Preferredtestquery-NULL, properties---{user=******, password=******}, Propertycycle-&G T 0, statementcachenumdeferredclosethreads, 0, Testconnectiononcheckin, False, Testconnectiononcheckout False, Unreturnedconnectiontimeout, 0, Useroverrides, {}, Usestraditionalreflectiveproxies, false]

Spring4.1 uses C3P0 to load the configuration file to connect to the database, Access denied for user ' root ' @ ' localhost ' ERROR!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.