I saw the JDBCSampleActivator.java example. I edited my code:
<code>
package org.DX_57.osgi.SH_27.impl;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Properties;
import org.DX_57.osgi.SH_27.api.SessionHandle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.Filter;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
public class SessionHandleApp implements BundleActivator {
private static final String DSNAME = "jdbc/Oracle";
private ServiceTracker st;
@Override
public void start(BundleContext bc) throws Exception {
bc.registerService(SessionHandle.class.getName(), new
SessionHandleImpl(), new Properties());
Filter filter = bc.createFilter("(&" + "(" +
Constants.OBJECTCLASS
+ "=" + DataSource.class.getName() + ")" +
"(jndi-name="
+ DSNAME + ")" + ")");
st = new ServiceTracker(bc, filter, null) {
@Override
public Object addingService(ServiceReference reference)
{
DataSource ds = (DataSource)
context.getService(reference);
try {
ds.getConnection().toString();
} catch (SQLException e) {
}
return super.addingService(reference);
}
@Override
public void removedService(ServiceReference reference,
Object service) {
super.removedService(reference, service);
}
};
st.open();
}
public void stop(BundleContext bc) throws Exception {
bc.ungetService(bc.getServiceReference(SessionHandle.class.getName()));
st.close();
}
}
</code>
For now it still don't work because JNDI is used for datasource and
I haven't configured it yet. Is it possible to configure the activator to
search for JDBC Resource instead JNDI resource?
How I must configure the above example to do this?
Best wishes
Peter
--
[Message sent by forum member 'rcbandit']
View Post: http://forums.java.net/node/883210