Example of setting properties thru reflection. This code is typically generated by tools or written by a system integrator:
javax.sql.DataSource makeDataSource(String dbname) throws Throwable { Class[] parameter = new Class[1]; parameter[0] = dbname.getClass(); DataSource ds = new EmbeddedDataSource40(); Class cl = ds.getClass(); Method setName = cl.getMethod("setDatabaseName", parameter); Object[] arg = new Object[1]; arg[0] = dbname; setName.invoke(ds, arg); return ds; }
Example on how to register a data source object with a JNDI naming service.
DataSource ds = makeDataSource("mydb"); Context ctx = new InitialContext(); ctx.bind("jdbc/MyDB", ds);
Example on how to retrieve a data source object from a JNDI naming service.
Context ctx = new InitialContext(); DataSource ds = (DataSource)ctx.lookup("jdbc/MyDB");
|
|
|
|
|
|