Unable to connect to any hosts due to exception

java.sql.SQLException: Unable to connect to any hosts due to exception: java.lang.ArrayIndexOutOfBoundsException: 40
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1797)
at com.mysql.jdbc.Connection.<init>(Connection.java:562)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:361)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at org.apache.commons.dbcp.DriverManagerConnectionFactory.createConnection(DriverManagerConnectionFactory.java:48)
at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290)
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:771)
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:95)
at com.community.util.ConnectionPool.getConnection(ConnectionPool.java:56)
at com.community.manager.ModelManager.getConnection(ModelManager.java:16)
at com.community.manager.MovieManager.main(MovieManager.java:48)


链接mysql的时候发现,数据库名称跟这个异常直接相关,

1 数据库名称里不能包含下划线等特殊字符。

2 数据库名称不能太长。

3 如果正常的数据库名称也出现这种问题,偶的解决方法是重装mysql,换数据库名称。

最主要的原因是:java的mysql驱动jar和当前的mysql版本不兼容造成的,稳定版是 mysql-connector-java-5.0.3.jar

你可能感兴趣的:(java,apache,sql,mysql,jdbc)