none
java连接SQL server2005,每秒写入60条数据,有时抛出1433 has faile错误 RRS feed

  • 问题

  • java连接SQL server2005,每秒写入60条数据,有时抛出1433 has faile错误。
    1433端口已打开,在本机连接SQL Server,连接正常,跑一天,会出现上百条这样的异常信息。
    错误信息:
    com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: Address already in use: connect. Please verify the connection properties and check that a SQL Server instance is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port. 

    程序:
    连接:
    static String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
    static String dbURL = "jdbc:sqlserver://localhost:1433;instanceName=SQL2005; DatabaseName=db";
    static String userName = "sa";
    static String userPwd = "";
    static Connection conn = null;
    static Statement stms=null;
    static ResultSet rs=null;

    每次写入数据,调用子函数rec,在子函数rec中打开并更新:
    private static void rec(String x,String y,String LTime,String id) {
      try {
        Class.forName(driverName);
        conn = DriverManager.getConnection(dbURL, userName, userPwd);
        stms=conn.createStatement();
        String sqlStr="update Pos set X="+x+",Y="+y+",lastTime='"+LTime+"' where ID="+id;
        System.out.println(sqlStr);
        stms.execute(sqlStr);
        System.out.println("SQL SRV Connection Successful!");
             } 
      catch (Exception e) {
    i++;
    System.err.println("err.in rec:"+i+e);
    createLog("err.in rec:"+i+e+" MSG:"+ msg2);
        }

      finally{
        try{
         if(!dsocket.isClosed())
    dsocket.close();
         if(rs!=null)rs.close();
         if(stms!=null)stms.close();
         if(conn!=null)conn.close();
        } catch(SQLException e){
         e.printStackTrace();
         createLog("err.in rec SQL:"+i+e+" MSG:"+ msg2);
        }
        catch(Exception e){
         e.printStackTrace();
         createLog("err.in rec:"+i+e+" MSG:"+ msg2);
        }
    }// finally
     }

    请大虾们帮忙看看~有人说用程序池,不知道是否可行?应该怎么改成程序池的连接方式?谢谢!
    2012年11月22日 1:13