• leverage RDBMS connections from custom servlet

    By Michael Bourak 7 years ago

    Hi,

    In my app I use extlib RDBMS feature on an XPages to retrieve data from a database (SQLServer in fact). All works ok.
    Now, I've developped a custom servlet inside my database (as in the XPagesExt.nsf db) and would like to reuse the connections.


    What I experienced is that :

    - if the xpages containing the rdbms connections has already been visited, all works ok on my servlet

    - if not, the JDBC connections is not found : as if it's not been initialized or something like that

     

    Is there a way to init the connections in my custom servlet ?

     

    Here is the stack trace, mssql1 is the name of my connection.

     

    28/11/2011 15:04:29 HTTP JVM: java.sql.SQLException
    28/11/2011 15:04:29 HTTP JVM: at com.ibm.xsp.extlib.util.JdbcUtil.createNamedConnection(JdbcUtil.java:88)
    28/11/2011 15:04:29 HTTP JVM: at com.ibm.xsp.extlib.util.JdbcUtil.getConnection(JdbcUtil.java:68)
    28/11/2011 15:04:29 HTTP JVM: at com.evodial.phone.PhoneDAO.getPhoneById(PhoneDAO.java:95)
    28/11/2011 15:04:29 HTTP JVM: at com.evodial.printing.PrintingServletFactory$EchoEngine.processRequest(PrintingServletFactory.java:67)
    28/11/2011 15:04:29 HTTP JVM: at com.ibm.xsp.extlib.services.servlet.ServiceServlet.service(ServiceServlet.java:48)
    28/11/2011 15:04:29 HTTP JVM: at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
    28/11/2011 15:04:29 HTTP JVM: at com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:576)
    28/11/2011 15:04:29 HTTP JVM: at com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1267)
    28/11/2011 15:04:29 HTTP JVM: at com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:847)
    28/11/2011 15:04:29 HTTP JVM: at com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:796)
    28/11/2011 15:04:29 HTTP JVM: at com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:565)
    28/11/2011 15:04:29 HTTP JVM: at com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1251)
    28/11/2011 15:04:29 HTTP JVM: at com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:598)
    28/11/2011 15:04:29 HTTP JVM: at com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:421)
    28/11/2011 15:04:29 HTTP JVM: at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:341)
    28/11/2011 15:04:29 HTTP JVM: at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:297)
    28/11/2011 15:04:29 HTTP JVM: at com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:272)
    28/11/2011 15:04:29 HTTP JVM: Caused by:
    28/11/2011 15:04:29 HTTP JVM: javax.naming.NameNotFoundException: comp/env/jdbc/mssql1
    28/11/2011 15:04:29 HTTP JVM: at com.ibm.pvc.jndi.internal.provider.java.FlatMappingContext.lookup(FlatMappingContext.java:118)
    28/11/2011 15:04:29 HTTP JVM: at com.ibm.pvc.jndi.internal.provider.java.FlatMappingContext.lookup(FlatMappingContext.java:140)
    28/11/2011 15:04:29 HTTP JVM: at javax.naming.InitialContext.lookup(InitialContext.java:436)
    28/11/2011 15:04:29 HTTP JVM: at com.ibm.xsp.extlib.util.JdbcUtil.createNamedConnection(JdbcUtil.java:82)

    • Try this way

      By Andrejus Chaliapinas 7 years ago

      Hi Michael,

      Could you try this way of enforced NSF based connection initialization for your servlet:

      JdbcDataSourceProvider.resetLocalProvider();

       

      Please let me know if it works or not for your scenario.

      • Perfect !

        By Michael Bourak 7 years ago

        Thanks a lot !