连接不上数据库

来源:2-7 验证Dao

qq_分享_03220023

2018-05-23

警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@48809789 -- 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 attempts (10). Last acquisition attempt exception: 

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

用户名,密码都没错,jdbc的配置也没错误,改变访问上限acquireRetryAttempts也没用。。。也改过my.ini,,,都没什么效果..

这是全部的报错

五月 23, 2018 8:45:28 下午 org.springframework.test.context.support.DefaultTestContextBootstrapper getDefaultTestExecutionListenerClassNames

信息: Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]

五月 23, 2018 8:45:28 下午 org.springframework.test.context.support.DefaultTestContextBootstrapper getTestExecutionListeners

信息: Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@4157f54e, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@90f6bfd, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@47f6473, org.springframework.test.context.support.DirtiesContextTestExecutionListener@15975490, org.springframework.test.context.transaction.TransactionalTestExecutionListener@6b143ee9, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@1936f0f5]

五月 23, 2018 8:45:28 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions

信息: Loading XML bean definitions from class path resource [spring/spring-dao.xml]

五月 23, 2018 8:45:29 下午 org.springframework.context.support.GenericApplicationContext prepareRefresh

信息: Refreshing org.springframework.context.support.GenericApplicationContext@51565ec2: startup date [Wed May 23 20:45:29 CST 2018]; root of context hierarchy

五月 23, 2018 8:45:29 下午 com.mchange.v2.log.MLog <clinit>

信息: MLog clients using java 1.4+ standard logging.

五月 23, 2018 8:45:30 下午 com.mchange.v2.c3p0.C3P0Registry banner

信息: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]

20:45:30.958 [main] DEBUG org.apache.ibatis.logging.LogFactory - Logging initialized using 'class org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter.

20:45:31.217 [main] DEBUG org.apache.ibatis.io.VFS - Class not found: org.jboss.vfs.VFS

20:45:31.217 [main] DEBUG org.apache.ibatis.io.JBoss6VFS - JBoss 6 VFS API is not available in this environment.

20:45:31.219 [main] DEBUG org.apache.ibatis.io.VFS - Class not found: org.jboss.vfs.VirtualFile

20:45:31.221 [main] DEBUG org.apache.ibatis.io.VFS - VFS implementation org.apache.ibatis.io.JBoss6VFS is not valid in this environment.

20:45:31.222 [main] DEBUG org.apache.ibatis.io.VFS - Using VFS adapter org.apache.ibatis.io.DefaultVFS

20:45:31.223 [main] DEBUG org.apache.ibatis.io.DefaultVFS - Find JAR URL: file:/C:/Users/Administrator/eclipse-workspace/o2o/target/classes/com/o2o/entity

20:45:31.224 [main] DEBUG org.apache.ibatis.io.DefaultVFS - Not a JAR: file:/C:/Users/Administrator/eclipse-workspace/o2o/target/classes/com/o2o/entity

20:45:31.316 [main] DEBUG org.apache.ibatis.io.DefaultVFS - Reader entry: Area.class

20:45:31.318 [main] DEBUG org.apache.ibatis.io.DefaultVFS - Reader entry: HeadLine.class

20:45:31.320 [main] DEBUG org.apache.ibatis.io.DefaultVFS - Reader entry: LocalAuth.class

20:45:31.322 [main] DEBUG org.apache.ibatis.io.DefaultVFS - Reader entry: PersonInfo.class

20:45:31.324 [main] DEBUG org.apache.ibatis.io.DefaultVFS - Reader entry: Product.class

20:45:31.328 [main] DEBUG org.apache.ibatis.io.DefaultVFS - Reader entry: ProductCategory.class

20:45:31.330 [main] DEBUG org.apache.ibatis.io.DefaultVFS - Reader entry: ProductImg.class

20:45:31.331 [main] DEBUG org.apache.ibatis.io.DefaultVFS - Reader entry: Shop.class

20:45:31.333 [main] DEBUG org.apache.ibatis.io.DefaultVFS - Reader entry: ShopCategory.class

20:45:31.335 [main] DEBUG org.apache.ibatis.io.DefaultVFS - Reader entry: WechatAuth.class

20:45:31.336 [main] DEBUG org.apache.ibatis.io.DefaultVFS - Listing file:/C:/Users/Administrator/eclipse-workspace/o2o/target/classes/com/o2o/entity

20:45:31.337 [main] DEBUG org.apache.ibatis.io.DefaultVFS - Find JAR URL: file:/C:/Users/Administrator/eclipse-workspace/o2o/target/classes/com/o2o/entity/Area.class

20:45:31.337 [main] DEBUG org.apache.ibatis.io.DefaultVFS - Not a JAR: file:/C:/Users/Administrator/eclipse-workspace/o2o/target/classes/com/o2o/entity/Area.class

20:45:31.340 [main] DEBUG org.apache.ibatis.io.DefaultVFS - Reader entry: ����

20:45:31.386 [main] DEBUG org.apache.ibatis.io.ResolverUtil - Checking to see if class com.o2o.entity.Area matches criteria [is assignable to Object]

20:45:31.388 [main] DEBUG org.apache.ibatis.io.ResolverUtil - Checking to see if class com.o2o.entity.HeadLine matches criteria [is assignable to Object]

20:45:31.391 [main] DEBUG org.apache.ibatis.io.ResolverUtil - Checking to see if class com.o2o.entity.LocalAuth matches criteria [is assignable to Object]

20:45:31.393 [main] DEBUG org.apache.ibatis.io.ResolverUtil - Checking to see if class com.o2o.entity.PersonInfo matches criteria [is assignable to Object]

20:45:31.396 [main] DEBUG org.apache.ibatis.io.ResolverUtil - Checking to see if class com.o2o.entity.Product matches criteria [is assignable to Object]

20:45:31.398 [main] DEBUG org.apache.ibatis.io.ResolverUtil - Checking to see if class com.o2o.entity.ProductCategory matches criteria [is assignable to Object]

20:45:31.400 [main] DEBUG org.apache.ibatis.io.ResolverUtil - Checking to see if class com.o2o.entity.ProductImg matches criteria [is assignable to Object]

20:45:31.402 [main] DEBUG org.apache.ibatis.io.ResolverUtil - Checking to see if class com.o2o.entity.Shop matches criteria [is assignable to Object]

20:45:31.405 [main] DEBUG org.apache.ibatis.io.ResolverUtil - Checking to see if class com.o2o.entity.ShopCategory matches criteria [is assignable to Object]

20:45:31.407 [main] DEBUG org.apache.ibatis.io.ResolverUtil - Checking to see if class com.o2o.entity.WechatAuth matches criteria [is assignable to Object]

20:45:31.411 [main] DEBUG org.mybatis.spring.SqlSessionFactoryBean - Scanned package: 'com.o2o.entity' for aliases

20:45:31.510 [main] DEBUG org.mybatis.spring.SqlSessionFactoryBean - Parsed configuration file: 'class path resource [mybatis-config.xml]'

20:45:31.688 [main] DEBUG org.mybatis.spring.SqlSessionFactoryBean - Parsed mapper file: 'file [C:\Users\Administrator\eclipse-workspace\o2o\target\classes\mapper\AreaDao.xml]'

20:45:32.049 [main] DEBUG org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession

20:45:32.071 [main] DEBUG org.mybatis.spring.SqlSessionUtils - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@353352b6] was not registered for synchronization because synchronization is not active

五月 23, 2018 8:45:32 下午 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager

信息: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 2, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 10000, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 2vsfwq9v134ql8715on7qc|4386f16, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 2vsfwq9v134ql8715on7qc|4386f16, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost:3306/o2o?useSSL=false&serverTimezone=Hongkong&useUnicode=true&charset=utf8, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 30, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 10, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]

五月 23, 2018 8:45:34 下午 com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run

警告: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@e19d8ba -- 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 attempts (2). Last acquisition attempt exception: 

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)

at com.mysql.jdbc.Util.getInstance(Util.java:387)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:917)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)

at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2332)

at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2085)

at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795)

at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)

at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400)

at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327)

at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)

at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)

at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)

at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)

at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)

at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)

at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)

at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

Caused by: java.lang.NullPointerException

at com.mysql.jdbc.ConnectionImpl.getServerCharset(ConnectionImpl.java:3005)

at com.mysql.jdbc.MysqlIO.sendConnectionAttributes(MysqlIO.java:1916)

at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1845)

at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1215)

at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2255)

at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2286)

... 18 more

写回答

2回答

翔仔

2018-05-23

同学好,你可以试着先用你本地的mysql客户端连接你本地的mysql服务器,用的是跟配置一模一样的帐号密码以及端口ip,看看能否连上,我感觉应该也是连接不上的,如果是这样的话,可以先保证mysql客户端与服务器能连上。然后再来看看这类配置问题。

1
6
qq_分享_03220023
非常感谢!
2018-05-24
共6条回复

翔仔

2018-05-24

然后如果还不行,可以参照网上的例子写个连接数据库的demo.

https://www.yiibai.com/jdbc/jdbc-db-connections.html

然后看看会报错不

0
1
qq_分享_03220023
好的,我试试?
2018-05-24
共1条回复

Java双版本(SSM到SpringBoot)校园商铺全栈开发

SSM商铺V1.0,解决毕设痛点;SpringBoot商铺V2.0,满足工作刚需

5113 学习 · 8144 问题

查看课程