3 Replies Latest reply on Apr 7, 2008 5:44 AM by realvalkyrie

    DataSource.getConnection problem

    realvalkyrie

      Thank U 4 all from beginning !!!!!!!
      my code is below:


      private InitialContext initial = null;
      private DataSource dataSource = null;


      public synchronized Connection getConnection(String name) {
      try {
      if(name==null) name = "";
      initial = new InitialContext();
      dataSource = (DataSource) initial.lookup("java:/jdbc/"+name);
      Connection con = dataSource.getConnection();
      return con;
      } catch (SQLException e) {
      System.out.print("can not get connection ...java:/jdbc/"+name);
      System.out.println("SQLException cause ~~~"+e.getMessage());
      e.printStackTrace();
      return null;
      } catch (NamingException e1) {
      System.out.println("NamingException cause ~~~"+e1.getMessage());
      e1.printStackTrace();
      return null;
      } finally{
      try {
      if(initial!=null) initial.close();
      } catch (NamingException e) {
      System.out.println("Error Closing InitialContext cause---->"+e.getMessage());
      e.printStackTrace();
      }
      }
      }


      it always work perfect ,but sometimes the system will throw the follow Exception , this is the details:


      INFO [STDOUT] can not get connection...java:/jdbc/et
      ERROR [STDERR] java.sql.SQLException: JZ006: capture io exception :com.sybase.jdbc3.jdbc.SybConnectionDeadException: JZ0C0: the connection has already been closed .



      here is my -ds.xml configuration


      <no-tx-datasource>
      <jndi-name>jdbc/et</jndi-name>
      <connection-url>jdbc:sybase:Tds:127.0.0.1:2638?ServiceName=et</connection-url>
      <driver-class>com.sybase.jdbc3.jdbc.SybDriver</driver-class>
      <user-name>DBA</user-name>
      < p a s s w o r d>**</ p a s s w o r d >
      <idle-timeout-minutes>5</idle-timeout-minutes>
      <blocking - timeout - millis>10000</blocking - timeout - millis>
      <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.SybaseExceptionSorter</exception-sorter-class-name>
      <min-pool-size>10</min-pool-size>
      <max-pool-size>1000</max-pool-size>
      <prepared-statement-cache-size>0</prepared-statement-cache-size>

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

      </no-tx-datasource>



      help me please
      thank u everyone !!!!!!!!!!!!
      tips:
      shoud i add this issue in the xml files to avoid that exception ?
      <check-valid-connection-sql>some check sql</check-valid-connection-sql>


      and make the initialcontext , datasource to static ?