I had the same error, but I don't want to close the connection in my ejb
method, because if I do that, I can't work with my database. Is there any way
to keep the connection open and close it manually outside the ejb method?
Here's is my code:
index.jsp
| (...)
| Connection conn=null;
| String nombre_proceso="";
| try{
| InitialContext ctx = getInitialContext();
| paquetegestionDB.gestionDBHome home =
paquetegestionDB.gestionDBHome)ctx.lookup("gestionDB");
| paquetegestionDB.gestionDB the_ejb = home.create();
| conn=the_ejb.conectar();
| (...)
| ctx.close();
| the_ejb.remove();
| }
| catch(RemoteException e){
| (...)
| }
|
| finally
| {
| try
| {
| if (conn!=null)
| if (!conn.isClosed())
| conn.close();
| }catch(Exception ignore){ System.out.println("error......."); }
| }
|
This is my ejb method conectar:
| public static Connection conectar()
| throws SQLException, RemoteException
| {
| System.out.println("Intentamos hacer la conexiÃn");
| Context ctx = null;
| Hashtable ht = new Hashtable();
| Connection conn = null;
|
ht.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
| ht.put(Context.PROVIDER_URL,"localhost");
| //ht.put(Context.URL_PKG_PREFIXES,
"org.jboss.naming:org.jnp.interfaces");
| try
| {
| ctx = new InitialContext(ht);
| //ctx = new InitialContext();
| DataSource ds = (DataSource)ctx.lookup("java:/OracleDS");
| conn = ds.getConnection();
| System.out.println("Se ha realizado la conexi\363n con
\351xito");
| return conn;
| }
| catch(Exception e)
| {
| System.out.println("Error:" + e);
| e.printStackTrace();
| return null;
| }
| }
|
This is my oracle-ds.xml
| <datasources>
| <local-tx-datasource>
| <jndi-name>OracleDS</jndi-name>
| <connection-url>jdbc:oracle:thin:@ip:1521:schema</connection-url>
| <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
| <user-name>...</user-name>
| <password>...</password>
| <metadata>
| <type-mapping>Oracle9i</type-mapping>
| </metadata>
| </local-tx-datasource>
| </datasources>
|
And my ejb-jar.xml
| <ejb-jar>
| <enterprise-beans>
| <session>
| <display-name>gestionDBEJB</display-name>
| <ejb-name>gestionDB</ejb-name>
| <home>paquetegestionDB.gestionDBHome</home>
| <remote>paquetegestionDB.gestionDB</remote>
| <ejb-class>paquetegestionDB.gestionDBEJB</ejb-class>
| <session-type>Stateless</session-type>
| <transaction-type>Container</transaction-type>
|
| <resource-ref>
| <res-ref-name>OracleDS</res-ref-name>
| <res-type>javax.sql.DataSource</res-type>
| <res-auth>Application</res-auth>
| </resource-ref>
|
| </session>
| </enterprise-beans>
|
| <assembly-descriptor>
| <container-transaction>
| <method>
| <ejb-name>gestionDB</ejb-name>
| <method-name>*</method-name>
| </method>
| <trans-attribute>Required</trans-attribute>
| </container-transaction>
|
| <security-role>
| <description>Users</description>
| <role-name>users</role-name>
| </security-role>
| </assembly-descriptor>
| </ejb-jar>
|
And finally, my jboss.xml:
| <jboss>
| <enterprise-beans>
| <session>
| <ejb-name>gestionDB</ejb-name>
| <jndi-name>gestionDB</jndi-name>
| <resource-ref>
| <res-ref-name>OracleDS</res-ref-name>
| <jndi-name>java:/OracleDS</jndi-name>
| </resource-ref>
| </session>
| </enterprise-beans>
| </jboss>
|
And that's the error I get:
14:51:04,327 INFO [CachedConnectionManager] Closing a connection for you. Plea
se close them yourself: [EMAIL PROTECTED]
0
java.lang.Exception: STACKTRACE
at org.jboss.resource.connectionmanager.CachedConnectionManager.register
Connection(CachedConnectionManager.java:319)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateC
onnection(BaseConnectionManager2.java:477)
at org.jboss.resource.connectionmanager.BaseConnectionManager2$Connectio
nManagerProxy.allocateConnection(BaseConnectionManager2.java:838)
at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(Wrapp
erDataSource.java:102)
at paquetegestionDB.gestionDBEJB.conectar(gestionDBEJB.java:82)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
(..)
14:51:04,549 ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for ser
vlet jsp threw exception
java.lang.NullPointerException
at org.apache.jsp.index_jsp._jspService(index_jsp.java:232)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:324)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:2
92)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:157)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
lter.java:75)
(...)
Thanks in advance
Esther
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3861033#3861033
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3861033
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user