用JSP写了个网站,但是运行了一段时间后,Tomcat报了下面的错误:Error establishing socket.我的数据库是SQL Server2000,按照网上的说法.我检查端口是没有错误的.服务器我打SP3补丁的时候,说是有了更高级的补丁.网页里调用Bean里的数据连接完成后,我也关闭了连接.比如:
try { //connDB.close()
           if (connDB != null) connDB.close();
         }
         catch (Exception e) {
           e.printStackTrace(System.err);
         }
下面是我的Bean
package beans;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
public class connDB{
            Connection conn=null;
                Statement stmt=null;
                ResultSet rs=null;
    DataSource db;
Context initCtx=null; /***************************************************
        *功能:采用数据连接池
****************************************************/
public connDB(){
try{
initCtx=new InitialContext();
            db=(DataSource)initCtx.lookup("java:comp/env/jdbc/aslan");
}catch(Exception e){
System.err.println(e.getMessage());
}
}
 /***************************************************
        *method name: executeQuery()
        *功能:执行查询操作。
        *return value: ResultSet
****************************************************/
public ResultSet executeQuery(String sql){
try{
conn=db.getConnection();
            stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    rs=stmt.executeQuery(sql);
}catch(SQLException e){
  System.err.println(e.getMessage());
}
return rs;
}
  /***************************************************
        *method name: executeUpdate()
        *功能:执行更新操作。
        *return value:result
****************************************************/
      public int executeUpdate(String sql){
  int result=0;
  try{
  conn=db.getConnection();
  stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
  result=stmt.executeUpdate(sql);
  }catch(SQLException e){
  result=0;
  }
  return result;
  }  
  
public int executeUpdate_id(String sql){
  int result=0;
  try{
  conn=db.getConnection();
  stmt=conn.createStatement(1004,1007);
  result=stmt.executeUpdate(sql);
  String ID = "select @@IDENTITY as id";
  rs = stmt.executeQuery(ID);
    if(rs.next())
            {
                int autoID = rs.getInt("id");
                result = autoID;
            }   }catch(SQLException e){
  result=0;
  }
  return result;
  }
 /***************************************************
        *method name: close()
        *功能:关闭数据库链接
        *return value:  void
****************************************************/
 public void close(){
        
 try { //rs.close()
           if (rs != null) rs.close();
         }
         catch (Exception e) {
           e.printStackTrace(System.err);
         }finally{
try{
if (rs != null) rs.close();
}catch(Exception ex){}
}         try { //stmt.close()
           if (stmt != null) stmt.close();
         }
         catch (Exception e) {
           e.printStackTrace(System.err);
         }finally{
 try{
 if (stmt != null) stmt.close();
 }catch(Exception ex){}
 }         try { //conn.close()
           if (conn != null) {
             conn.close();
           }
         }
         catch (Exception e) {
           e.printStackTrace(System.err);
         }finally{
 try{
 if(conn!=null) conn.close();
 }catch(Exception ex){}
 }
          try { //initCtx.close()
           if (initCtx != null) initCtx.close();
         }
         catch (Exception e) {
           e.printStackTrace(System.err);
         }finally{
 try{
 if (initCtx != null) initCtx.close();
 }catch(Exception ex){}
 }       }
}这个错误:Error establishing socket怎么解决呢.谢谢大家的帮助.

解决方案 »

  1.   

    Error establishing socket
    连接不上数据库,确认将ms的驱动放到 WEB-INF\lib\ 下了吗
      

  2.   

    确定.是运行一段时间后回出现这个问题的.Tomcat重新启动后,又恢复正常.哎,不知道是什么问题.网上找了资料,都没有确实的解决办法.
      

  3.   

    对的.但是我在用完了连接后,都采取了关闭的措施.比如这样
    String sql=select top 5 * from tb_aslandt order by aslandtfist desc,intime descResultSet rs_product=connDB.executeQuery(sql)
    while(rs_aslandt.next()){
    读取数据操作
    }//下面是关闭
    try { //rs_aslandt.close()
               if (rs_aslandt != null) rs_aslandt.close();
             }
             catch (Exception e) {
               e.printStackTrace(System.err);
             }finally{
    try{
    if (rs_aslandt != null) rs_aslandt.close();
    }catch(Exception ex){}
    }

    try { //connDB.close()
               if (connDB != null) connDB.close();
             }
             catch (Exception e) {
               e.printStackTrace(System.err);
             }
    大家看看,这样还有什么问题吗?谢谢了