Can you create a MySql DataSource in a Context?
I am trying to learn how to use datasources to get connections, and I am successful in doing this for the MysqlDataSource in this way:
connection = mysqlDataSource.getConnection();
However, I want to try to retrieve the connection via a Context,
and am unsuccessful in creating the initial association, like this:
MysqlDataSource dataSource =new MysqlDataSource();
dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/test" );
dataSource.setUser( stringUser );
dataSource.setPassword( stringPass );
//
String stringDataSourceMYS ="com.mysql.jdbc.jdbc2.optional.MysqlDataSource";
Properties properties =new Properties();
properties.put( Context.INITIAL_CONTEXT_FACTORY, stringDataSourceMYS );
properties.put( Context.PROVIDER_URL ,"jdbc:mysql://127.0.0.1:3306/test" );
//
Context context =new InitialContext( properties );
context.bind("jdbc/mySql" , dataSource );
It renders the following error:
javax.naming.NoInitialContextException:
Cannot instantiate class: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
[Root exception is java.lang.ClassCastException]
This follows the example in the JDBC optional doc, but does not work.
I do not think this is a path issue (since it works w/o using the context bind).
I do not know what I need to make it "bind" properly.
Can anyone help with this? Thank You.

