0 Replies Latest reply on Apr 4, 2006 11:11 AM by Manjith Kumar

    DataSource failover while creating a connection in JBOSS 4.

    Manjith Kumar Newbie

      Hi,

      I get NullPointerException while trying to create a connection from the datasource.
      My Postgres-ds.xml is as follows:

      <?xml version="1.0" encoding="UTF-8"?>
      <datasources>
       <ha-local-tx-datasource>
      
       <jndi-name>PostgresDS</jndi-name>
       <use-java-context>false</use-java-context>
       <connection-url>jdbc:postgresql://192.168.149.49:5432/DNA_Mann</connection-url>
       <url-delimiter>|</url-delimiter>
       <driver-class>org.postgresql.Driver</driver-class>
       <user-name>postgres</user-name>
       <password>postgres</password>
       <metadata>
       <type-mapping>PostgreSQL 8.0</type-mapping>
       </metadata>
       </ha-local-tx-datasource>
      </datasources>


      and the code in my jsp is:

      InitialContext iniCtx = new InitialContext();
      
      DataSource ds = (javax.sql.DataSource)iniCtx.lookup("PostgresDS");
      
      System.out.println("The datasource is...."+ds.getClass());
      
      Connection conn = ds.getConnection();
      
      Statement stmt = conn.createStatement();
      
      ResultSet res = stmt.executeQuery(sql);
      


      WHEN I TRY TO RUN THIS I AM GETTING A NULL POINTER EXception
      The stack Trace is as follows:
      20:15:16,727 INFO [ChannelSocket] JK: ajp13 listening on /0.0.0.0:8009
      20:15:16,743 INFO [JkMain] Jk running ID=0 time=0/31 config=null
      20:15:16,743 INFO [Server] JBoss (MX MicroKernel) [4.0.2 (build: CVSTag=JBoss_4_0_2 date=200505022023)] Started in 55s:940ms
      20:15:33,806 INFO [STDOUT] The datasource is....org.jboss.resource.adapter.jdbc.WrapperDataSource@37504d
      20:17:16,511 INFO [STDOUT] The datasource is....org.jboss.resource.adapter.jdbc.WrapperDataSource@c759f5
      20:17:16,511 WARN [JBossManagedConnectionPool] Throwable while attempting to get a new connection: null
      java.lang.NullPointerException
      at org.jboss.resource.adapter.jdbc.local.HALocalManagedConnectionFactory.doCreateManagedConnection(HALocalManagedConnectionFactory.jav
      a:82)
      at org.jboss.resource.adapter.jdbc.local.HALocalManagedConnectionFactory.createManagedConnection(HALocalManagedConnectionFactory.java:
      75)
      at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.createConnectionEventListener(InternalManagedConnectionPool.java
      :508)
      at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:207)
      at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:534)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:395)
      at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:297)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:447)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:8
      74)
      at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:103)
      at org.apache.jsp.hello1_jsp._jspService(org.apache.jsp.hello1_jsp:86)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      at java.lang.Thread.run(Thread.java:534)