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

    DataSource.getConnection problem

    qi chengwei Newbie

      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());
      return null;
      } catch (NamingException e1) {
      System.out.println("NamingException cause ~~~"+e1.getMessage());
      return null;
      } finally{
      try {
      if(initial!=null) initial.close();
      } catch (NamingException e) {
      System.out.println("Error Closing InitialContext cause---->"+e.getMessage());

      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

      < p a s s w o r d>**</ p a s s w o r d >
      <blocking - timeout - millis>10000</blocking - timeout - millis>



      help me please
      thank u everyone !!!!!!!!!!!!
      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 ?