-
1. Re: How can I get a connection from a connection pool?
merith Aug 23, 2001 4:54 AM (in response to merith)Help is not needed. I found it.
Thanks. -
2. Re: How can I get a connection from a connection pool?
merith Sep 13, 2001 4:47 AM (in response to merith)I use the following private method to get a pool connection. I don't know if it a JTS connection. Does anyone know if it does?
private Connection getConnection() throws SQLException {
try
{
Context jndiContext = new InitialContext();
DataSource ds = (DataSource)jndiContext.lookup("java:/poolName");
return ds.getConnection();
}
catch (Exception ex)
{
throw new EJBException(ex);
}
} -
3. Re: How can I get a connection from a connection pool?
luckystar_007 Feb 26, 2002 10:05 PM (in response to merith)I think maybe it is a good idea.But I want to know more detail about jndi name:
if in jboss.jcml ,there is :
should I use:
lookup("java:/InstantDB") ? -
4. Re: How can I get a connection from a connection pool?
luckystar_007 Feb 26, 2002 10:54 PM (in response to merith)I think maybe there still be some puzzle, I have an example,I make an EJB:
package quay;
import javax.ejb.*;
import javax.sql.XAConnection;
import javax.sql.XADataSource;
import javax.naming.InitialContext;
import javax.naming.Context;
public class myquayBean implements SessionBean{
public void ejbCreate(){}
public void ejbActivate(){}
public void ejbPassivate(){}
public void ejbRemove(){}
public void setSessionContext(SessionContext ctx){}
public String say()
{
//return "Hi,my quay!";
try{
XAConnection myconn=getConnection();
if (myconn!=null){
return "Hi, my quay!";
}else{
return "conn null!";
}
}catch(Exception e){
return "Exception!";
}
}
private XAConnection getConnection() throws Exception {
try{
Context jndiContext = new InitialContext();
XADataSource ds = (XADataSource)jndiContext.lookup("java:/InstantDB");
return ds.getXAConnection();
}catch (Exception ex){
ex.printStackTrace();
throw new EJBException(ex);
}
}
}
after deploy and run, I found that the jboss console says:
java.lang.ClassCastException: org.opentools.minerva.jdbc.xa.XAPoolDataSource
Then, should I cast the jndi lookup result to
org.opentools.minerva.jdbc.xa.XAPoolDataSource ?