Discussion:
Problem with in-memory connector MXJ
Pierre Goupil
2011-12-21 14:24:02 UTC
Permalink
Good afternoon,

I'm currently trying and configure MySQL in order to have an in-memory
database in my unit tests. My environment is: Linux 3.0.0, Java 6 openJDK,
MySQL connector 5.0.7 and MXJ 5.0.12.

Here's my code:

------------------
String driver = System.getProperty("SQL_DRIVER", "com.mysql.jdbc.Driver");
String defaultUrl =
"jdbc:mysql:///test?propertiesTransform=com.mysql.management.jmx.ConnectorMXJPropertiesTransform";

String url = System.getProperty("SQL_URL", defaultUrl);
String user = System.getProperty("SQL_USER", "root");
String password = System.getProperty("SQL_PW", "");

Class.forName(driver);

Connection conn = DriverManager.getConnection(url, user, password);
------------------

I get an exception at the last line:

------------------
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0,
Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:571)
at java.util.ArrayList.get(ArrayList.java:349)
at
com.mysql.management.jmx.ConnectorMXJPropertiesTransform.<init>(ConnectorMXJPropertiesTransform.java:63)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at java.lang.Class.newInstance0(Class.java:372)
at java.lang.Class.newInstance(Class.java:325)
at
com.mysql.jdbc.NonRegisteringDriver.parseURL(NonRegisteringDriver.java:639)
at
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:280)
at java.sql.DriverManager.getConnection(DriverManager.java:620)
at java.sql.DriverManager.getConnection(DriverManager.java:200)
at mxj.Start.main(Start.java:25)
------------------

A clue, anyone? Any help will be much appreciated.

Regards,

Pierre Goupil
--
Si tu penses que la violence ne résout rien, c'est que tu n'as pas tapé
assez fort.
Pierre Goupil
2011-12-29 16:05:48 UTC
Permalink
Mmmmmh. It looks like it works!

Thanx!

Pierre
Try something like this... please change some variables based on your
==============================**=
Connection con = null ;
Class.forName( "org.gjt.mm.mysql.Driver" ).newInstance( ) ;
Properties prop = new Properties( ) ;
prop.put( "user", "myusername" ) ;
prop.put( "password", "mypassword" ) ;
prop.put( "characterEncoding", "utf8" ) ;
prop.put( "useUnicode", "true" ) ;
prop.put( "zeroDateTimeBehavior", "convertToNull" ) ;
prop.put( "useServerPrepStmts", "false" ) ;
prop.put( "cachePreparedStatements", "true" ) ;
String url = "jdbc:mysql://localhost/**mysqldbname";
con = DriverManager.getConnection( url, prop ) ;
==================
Celil
Post by Pierre Goupil
Good afternoon,
I'm currently trying and configure MySQL in order to have an in-memory
database in my unit tests. My environment is: Linux 3.0.0, Java 6 openJDK,
MySQL connector 5.0.7 and MXJ 5.0.12.
------------------
String driver = System.getProperty("SQL_**DRIVER",
"com.mysql.jdbc.Driver");
String defaultUrl =
"jdbc:mysql:///test?**propertiesTransform=com.mysql.**management.jmx.**
ConnectorMXJPropertiesTransfor**m";
String url = System.getProperty("SQL_URL", defaultUrl);
String user = System.getProperty("SQL_USER", "root");
String password = System.getProperty("SQL_PW", "");
Class.forName(driver);
Connection conn = DriverManager.getConnection(**url, user, password);
------------------
------------------
0,
Size: 0
at java.util.ArrayList.**rangeCheck(ArrayList.java:571)
at java.util.ArrayList.get(**ArrayList.java:349)
at
com.mysql.management.jmx.**ConnectorMXJPropertiesTransfor**m.<init>(**
ConnectorMXJPropertiesTransfor**m.java:63)
at sun.reflect.**NativeConstructorAccessorImpl.**newInstance0(Native
Method)
at
sun.reflect.**NativeConstructorAccessorImpl.**newInstance(**
NativeConstructorAccessorImpl.**java:57)
at
sun.reflect.**DelegatingConstructorAccessorI**mpl.newInstance(**
DelegatingConstructorAccessorI**mpl.java:45)
at java.lang.reflect.Constructor.**newInstance(Constructor.java:**532)
at java.lang.Class.newInstance0(**Class.java:372)
at java.lang.Class.newInstance(**Class.java:325)
at
com.mysql.jdbc.**NonRegisteringDriver.parseURL(**
NonRegisteringDriver.java:639)
at
com.mysql.jdbc.**NonRegisteringDriver.connect(**
NonRegisteringDriver.java:280)
at java.sql.DriverManager.**getConnection(DriverManager.**java:620)
at java.sql.DriverManager.**getConnection(DriverManager.**java:200)
at mxj.Start.main(Start.java:25)
------------------
A clue, anyone? Any help will be much appreciated.
Regards,
Pierre Goupil
--
Si tu penses que la violence ne résout rien, c'est que tu n'as pas tapé
assez fort.
Loading...