Hi,
Want to use Errai-bus for database access and tried to follow the code from an earlier question(Errai + DataSource Oct 25, 2010 by dan.dan) .
My server code is like:
package DbErrai.server;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.sql.DataSource;
import org.jboss.errai.bus.client.api.Message;
import org.jboss.errai.bus.client.api.MessageCallback;
import org.jboss.errai.bus.client.api.base.MessageBuilder;
import org.jboss.errai.bus.client.framework.MessageBus;
import org.jboss.errai.bus.server.annotations.Service;
@Service
public class DbErraiService implements MessageCallback {
@Inject
MessageBus bus;
@Resource(name = "mapobjectdb", mappedName = "java:/mapobjectdb")
DataSource ds;
Connection con;
PreparedStatement pstm;
ResultSet rs;
@Override
public void callback(Message message) {
try {
con = ds.getConnection();
MessageBuilder.createConversation(message).subjectProvided()
.withValue("Connection opened").done().reply();
con.close();
} catch (Exception e) {
MessageBuilder.createConversation(message).subjectProvided()
.withValue(e.toString()).done().reply();
e.printStackTrace();
}
}
}
But I get NullPointerException at: con = ds.getConnection();
In another application where gwt rpc is used, connection to database works OK with same resource declaration
What am I doing wrong?
Regards
stab