3 Replies Latest reply on Nov 21, 2006 1:16 PM by Cindy Taylor

    Problem Connection to Sybase Adaptive Server using jndi and

    Chandrasekaran R Newbie

      Hi,

      I try to connect to Sybase Adaptive Server using jndi.

      I am getting the following exception.

      java.sql.SQLException: Connection handle has been closed and is unusable
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.jboss.resource.adapter.jdbc.WrappedConnection.checkStatus(WrappedConnection.java:526)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.jboss.resource.adapter.jdbc.WrappedConnection.checkTransaction(WrappedConnection.java:513)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:169)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.mindtree.bl.compliance.ComplianceSqlManager.getEmployeeByLogin(ComplianceSqlManager.java:107)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.mindtree.bl.compliance.ComplianceSqlManager.getAllAnnouncements(ComplianceSqlManager.java:46)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.apache.jsp.WEB_002dINF.jsp.offline.system.modules.org_mindtree_bl.elements.check_005fcompliance_jsp._jspService(org.apache.jsp.WEB_002dINF.jsp.offline.system.modules.org_mindtree_bl.elements.check_005fcompliance_jsp:87)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
      2006-11-07 15:02:09,189 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      2006-11-07 15:02:09,189 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:574)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:499)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.opencms.flex.CmsFlexRequestDispatcher.includeExternal(CmsFlexRequestDispatcher.java:193)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.opencms.flex.CmsFlexRequestDispatcher.include(CmsFlexRequestDispatcher.java:171)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.opencms.loader.CmsJspLoader.service(CmsJspLoader.java:416)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.opencms.flex.CmsFlexRequestDispatcher.includeInternalWithCache(CmsFlexRequestDispatcher.java:419)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.opencms.flex.CmsFlexRequestDispatcher.include(CmsFlexRequestDispatcher.java:175)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.opencms.jsp.CmsJspTagInclude.includeTagAction(CmsJspTagInclude.java:218)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.opencms.jsp.CmsJspTagInclude.doEndTag(CmsJspTagInclude.java:349)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.apache.jsp.WEB_002dINF.jsp.offline.system.modules.org_mindtree_bl.templates.main_jsp._jspx_meth_cms_include_0(org.apache.jsp.WEB_002dINF.jsp.offline.system.modules.org_mindtree_bl.templates.main_jsp:217)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.apache.jsp.WEB_002dINF.jsp.offline.system.modules.org_mindtree_bl.templates.main_jsp._jspService(org.apache.jsp.WEB_002dINF.jsp.offline.system.modules.org_mindtree_bl.templates.main_jsp:69)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
      2006-11-07 15:02:09,189 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      2006-11-07 15:02:09,189 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:574)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:499)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.opencms.flex.CmsFlexRequestDispatcher.includeExternal(CmsFlexRequestDispatcher.java:193)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.opencms.flex.CmsFlexRequestDispatcher.include(CmsFlexRequestDispatcher.java:171)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.opencms.loader.CmsJspLoader.service(CmsJspLoader.java:416)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.opencms.flex.CmsFlexRequestDispatcher.includeInternalWithCache(CmsFlexRequestDispatcher.java:419)
      2006-11-07 15:02:09,189 INFO [STDOUT] at org.opencms.flex.CmsFlexRequestDispatcher.include(CmsFlexRequestDispatcher.java:175)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.opencms.jsp.CmsJspTagInclude.includeTagAction(CmsJspTagInclude.java:218)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.opencms.jsp.CmsJspTagInclude.doEndTag(CmsJspTagInclude.java:349)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.jsp.WEB_002dINF.jsp.offline.sites.default_.blackrock.intranet.corpdir.index_jsp._jspx_meth_cms_include_0(org.apache.jsp.WEB_002dINF.jsp.offline.sites.default_.blackrock.intranet.corpdir.index_jsp:727)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.jsp.WEB_002dINF.jsp.offline.sites.default_.blackrock.intranet.corpdir.index_jsp._jspService(org.apache.jsp.WEB_002dINF.jsp.offline.sites.default_.blackrock.intranet.corpdir.index_jsp:78)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
      2006-11-07 15:02:09,204 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      2006-11-07 15:02:09,204 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:574)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:499)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.opencms.flex.CmsFlexRequestDispatcher.includeExternal(CmsFlexRequestDispatcher.java:193)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.opencms.flex.CmsFlexRequestDispatcher.include(CmsFlexRequestDispatcher.java:171)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.opencms.loader.CmsJspLoader.service(CmsJspLoader.java:416)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.opencms.flex.CmsFlexRequestDispatcher.includeInternalWithCache(CmsFlexRequestDispatcher.java:419)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.opencms.flex.CmsFlexRequestDispatcher.include(CmsFlexRequestDispatcher.java:175)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.opencms.loader.CmsJspLoader.dispatchJsp(CmsJspLoader.java:450)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.opencms.loader.CmsJspLoader.load(CmsJspLoader.java:395)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.opencms.loader.CmsResourceManager.loadResource(CmsResourceManager.java:711)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.opencms.main.OpenCmsCore.showResource(OpenCmsCore.java:1337)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.opencms.main.OpenCmsServlet.doGet(OpenCmsServlet.java:139)
      2006-11-07 15:02:09,204 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
      2006-11-07 15:02:09,204 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:307)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:385)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:748)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:678)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:871)
      2006-11-07 15:02:09,204 INFO [STDOUT] at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
      2006-11-07 15:02:09,204 INFO [STDOUT] at java.lang.Thread.run(Unknown Source)
      I am using javax.sql.DataSource to get connection.

      I have the following settings:

      sybase-ds.xml
      __________________


      <local-tx-datasource>
      <jndi-name>DSWriteSybaseServer</jndi-name>
      <connection-url>jdbc:sybase:Tds:dt969-testserver:5003/testdb?charset=utf8</connection-url>
      <driver-class>com.sybase.jdbc3.jdbc.SybDriver</driver-class>
      <user-name>blackrock</user-name>
      blackrock
      <max-pool-size>20</max-pool-size>
      <min-pool-size>5</min-pool-size>
      <idle-timeout-minutes>5</idle-timeout-minutes>


      <type-mapping>Sybase</type-mapping>

      </local-tx-datasource>



      web.xml
      _____________

      <resource-ref>
      DB Connection
      <res-ref-name>jdbc/DSWriteSybaseServer</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>

      jboss-web.xml
      ___________________

      <jboss-web>

      <resource-ref>
      <res-ref-name>jdbc/DSWriteSybaseServer</res-ref-name>
      <jndi-name>DSWriteSybaseServer</jndi-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>

      </jboss-web>

      And my java code:

      private static Connection getConnectionFromDataSource()
      {
      Connection sqlConnection = null;

      String dbDataSource = PropertyFileReader.getProperty("db.datasource");
      Context initContext;
      try
      {
      initContext = new InitialContext();
      DataSource ds = null;
      try
      {
      ds = (DataSource) initContext.lookup(dbDataSource);
      if (ds == null) {
      throw new Exception("Error: No DataSource");
      }
      sqlConnection = ds.getConnection();
      }
      catch (NamingException e)
      {
      log.error("[getConnectionFromDriver] "+e.getMessage());
      e.printStackTrace();
      log.debug("getConnectionFromDriver: SQLException");
      }
      catch (SQLException sqle)
      {
      log.error("[getConnectionFromDriver] "+sqle.getMessage());
      System.out.println("ConnectionManager Sql exception " +sqle.getMessage());
      sqle.printStackTrace();
      log.debug("getConnectionFromDriver: SQLException");
      }
      catch (Exception e)
      {
      log.error("[getConnectionFromDriver] "+e.getMessage());
      System.out.println("ConnectionManager Exception " + e.getMessage());
      e.printStackTrace();
      log.debug("getConnectionFromDriver: Exception");
      }
      finally
      {
      if (sqlConnection != null)
      sqlConnection.close();
      }
      }
      catch (NamingException e)
      {
      log.error("[getConnectionFromDriver] "+e.getMessage());
      e.printStackTrace();
      log.debug("getConnectionFromDriver: SQLException");
      }
      catch (SQLException sqle)
      {
      log.error("[getConnectionFromDriver] "+sqle.getMessage());
      sqle.printStackTrace();
      log.debug("getConnectionFromDriver: SQLException");
      }
      return sqlConnection;
      }

      If any body have solution please reply.

      Thanks,
      Chandrasekaran R