• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic