本文共 2423 字,大约阅读时间需要 8 分钟。
初学spring框架
今天在使用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 -> 1hgemm9a91lgxerek000n4|7494e528, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hgemm9a91lgxerek000n4|7494e528, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost:3306/book?Unicode=true&characterEncoding=utf8, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
之前用的是druid连接池,没有一点问题,网上搜了不少解决方法,说到缺了个jar包,mchange-commons-java-0.2.3.4.jar,但是加进去后也不对,可能是版本不对,作为初学者我最苦恼的就是找版本,然后我转念一想,还是直接改druid,
关于配置还有一个问题就是乱码问题,之前在idea设置url的时候是
jdbc:mysql://localhost:3306/book?Unicode=true&characterEncoding=utf8 但是转到eclipse的时候发现报错一直要求加; 一开始我将’&‘改成’;’ 发现连不上,最后网上一找发现应该在’&‘后加上’amp;’ 即<property name="url" value="jdbc:mysql://localhost:3306/book?Unicode=true&characterEncoding=utf8"></property>
再一个就是使用外部配置文件的时候,出现了乱码问题
我经过调试发现可能是我的eclipse配置成GBK,一直卡着点很难受,直接将value值赋值,完美跳过com.alibaba.druid.support.logging.JakartaCommonsLoggingImpl error严重: create connection SQLException, url: jdbc:mysql://localhost:3306/book?Unicode=true&characterEncoding=utf8, errorCode 1045, state 28000java.sql.SQLException: Access denied for user '黄ç�¿ä½³'@'localhost' (using password: YES)
配置文件:
username=rootpassword=123456url=jdbc:mysql://localhost:3306/book?Unicode=true&characterEncoding=utf8driverClassName=com.mysql.jdbc.DriverinitialSize=5maxActive=10
xml代码:
以上博文做法不对之处欢迎指正
转载地址:http://jakqf.baihongyu.com/