mysql jdbc got ArrayIndexOutOfBoundsException when database name length = 9
- by Thang Hoang
this code below will throw :
Exception in thread "main" java.sql.SQLException: Unable to connect to any hosts due to exception: java.lang.ArrayIndexOutOfBoundsException: 40
mysql 5.1, jdbc driver 5.1.21
if I change connection string to any database have name's lengh != 9, it will pass to print 'connected'. or I create other database as '123456789' it throw same exception.
I connect to other database on amazon s3, that have same name length, it throw java.lang.ArrayIndexOutOfBoundsException: 43. this database version is 'mysql Ver 14.14 Distrib 5.5.28, for debian-linux-gnu (i686) using readline 6.2
'
any idea of this weird mysql behavior, thanks
public class MysqlConnection {
public static void main(String[] args) throws Exception {
Connection conn = null;
String userName = "root";
String password = "123456";
String url = "jdbc:mysql://localhost:3306/test12345";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url,userName, password);
System.out.println ("Connected");
}
}