4 Replies Latest reply on Mar 26, 2009 5:01 AM by Gajanan More

    How can i access my own datasource in portlet jsp

    Gajanan More Newbie

      How can i access my own datasource in potlet jsp page. and is there any mapping is require to connect the datasource.

      please helpme to resolve this problem.

        • 1. Re: How can i access my own datasource in portlet jsp
          Peter Johnson Master

          You can do this the same way you would do it in an JSP page - use JNDI to access the data source and get a connection. However, I suggest that you do that work in the portlet code and simply pass the results to the JSP and let it format the page.

          • 2. Re: How can i access my own datasource in portlet jsp
            Gajanan More Newbie

            hi peter i really apperciate for your quick reply.


            I am using JNDI lookup for data source in my jsp page
            however i am getting NameNotFoundException.
            below is my jsp page:

            InitialContext ic = new InitialContext();
            System.out.println("After initial context");
            ds = (DataSource) ic.lookup("jdbc/mysql");

            and my web.xml contains:
            <resource-ref>
            jdbc/mysql
            <res-ref-name>jdbc/mysql</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
            </resource-ref>

            stacktrace:
            javax.naming.NameNotFoundException: jdbc not bound
            10:58:10,718 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
            10:58:10,718 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
            10:58:10,718 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
            10:58:10,718 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
            10:58:10,718 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
            10:58:10,718 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
            10:58:10,718 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialContext.java:392)
            10:58:10,718 ERROR [STDERR] at org.apache.jsp.jsp.Adventures_jsp._jspService(Adventures_jsp.java:83)
            10:58:10,718 ERROR [STDERR] at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
            10:58:10,718 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
            10:58:10,718 ERROR [STDERR] at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:387)
            10:58:10,718 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
            10:58:10,718 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
            10:58:10,718 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
            10:58:10,718 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            10:58:10,718 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            10:58:10,718 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
            10:58:10,718 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            10:58:10,718 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            10:58:10,718 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
            10:58:10,718 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
            10:58:10,718 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
            10:58:10,718 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
            10:58:10,718 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
            10:58:10,718 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
            10:58:10,718 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
            10:58:10,718 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            10:58:10,718 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
            10:58:10,718 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
            10:58:10,718 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
            10:58:10,718 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
            10:58:10,718 ERROR [STDERR] at java.lang.Thread.run(Thread.java:619)

            thanks in advance.

            • 3. Re: How can i access my own datasource in portlet jsp
              Vanghelle Vincent Newbie

              I defined my datasource in a "extranet-ds.xml" file, deployed in the deploy folder.

              My DS is set as :

              <datasources>
               <local-tx-datasource>
               <jndi-name>jdbc/TestIntranet</jndi-name>
               <connection-url>jdbc:postgresql://192.168.10.108:5432/Intranet</connection-url>
               <driver-class>org.postgresql.Driver</driver-class>
               <user-name>postgres</user-name>
               <password><![CDATA[]]></password>
               </local-tx-datasource>
              
              </datasources>
              


              And it works fine!

              • 4. Re: How can i access my own datasource in portlet jsp
                Gajanan More Newbie

                thanks vantek
                actually i was not updated the mysql_ds.xml file bec of that i got this error. now i updated and its working fine.