• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can I use EJBQL for BMP?

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I use EJBQL for BMP?
Thanks,
Murali
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To reassert sergiu's statement, EJBQL cannot be used in BMP.
It can only be used for CMP entity beans.
 
reply
    Bookmark Topic Watch Topic
  • New Topic