Get your Connection from the DataSource and fire away your SQL the
Context initial = new InitialContext(); DataSource ds = (DataSource)initial.lookup("Name-in-ds.xml"); Connection con = ds.getConnection();
In the code example...
DataSource ds = (DataSource)initial.lookup("Name-in-ds.xml");
... do you mean "DefaultDS" for "Name-in-ds.xml"?
Yes, it could be "java:/DefaultDS" or whatever your JNDI for the DS you are using is bound to.
If your dynamic queries aren't too complex you might be able to use dynamic JBoss-QL - it's an extension of EJB-QL which you can use dynamically.
Whilst you can't do everything that you can in SQL, it's useful if you have lots of different queries that could be written in EJB-QL but you can't define them all in advance.
We use it for an interface that dynamically queries the data controlled by our CMP entities.
There's details on how to use it in the JBossCMP for-pay documentation.