EJB-QL is made for usage inside CMP.
Inside BMP/Session Beans you have to use plain SQL. You have to get the Datasource from the container through
JDBC and than get a connection and use statements. Here's some code snippet I use from a Stateless Session Bean with
JBoss:
public CachedRowSet getAllUsers() throws BackEndException {
try{
con = getConnection();
//load data from the database
PreparedStatement pstm = con.prepareStatement("SELECT * FROM USERS");
CachedRowSet cache = new CachedRowSet();
cache.populate(pstm.executeQuery());
cache.beforeFirst();
pstm.close();
con.close();
return cache;
}catch (SQLException sqe) {
System.out.println("SQLException: " + sqe);
throw new BackEndException(BackEndErrors.GENERIC_SQLQUERY_ERROR + this.getClass());
}
}
private Connection getConnection() {
try{
InitialContext context = new InitialContext();
DataSource ds = (DataSource) context.lookup("java:/OracleDS");
return ds.getConnection();
}catch(Exception ex){
System.out.println("Error getting the Connection to the database!");
}
return null;
}
Hope this helps.
Cheers