Link to home
Start Free TrialLog in
Avatar of hgbdelphi
hgbdelphi

asked on

about "error establishing socket"??

hi,experts,in my project ,about some time (10s or 30s) ,the error" java.sql.SqLException:[Microsoft] [SQLServer:2000 driver for jdbc] Error establishing socket" will show in tomcat console.i use sqlserver2000 + sp3 + win2000 server,and my code like this:

<%@ page contentType="text/html; charset=gb2312" %>
<% request.setCharacterEncoding("gb2312"); %>
<%@ page import="java.sql.*"%>
<%
            String sqlDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
            String sqlJdbc = "jdbc:microsoft:sqlserver://btns:1433;DatabaseName=CommunityMedical";
            String sqlUser = "sa";
            String sqlPwd = "btn";
            try {
                  Class.forName(sqlDriver);
                  Connection conn = DriverManager.getConnection(sqlJdbc, sqlUser, sqlPwd);
                  java.sql.Statement stmt = conn.createStatement();
            java.sql.ResultSet rs=stmt.executeQuery("select 1");
            if(rs.next()){
              out.println("ok");
            }
            } catch (Exception e) {
                  out.println(e);
            }
%>

why the error is show????

thanks!
Avatar of hgbdelphi
hgbdelphi

ASKER

can any exters help me ,it's sqlserver2000's bug?but i use splserver2000+sp3,and when i use resin or tomcat the error is show in two server.
Avatar of TimYates
Do you ever close your Statements and Connections?

Try:

<%@ page contentType="text/html; charset=gb2312" %>
<% request.setCharacterEncoding("gb2312"); %>
<%@ page import="java.sql.*"%>
<%
          String sqlDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
          String sqlJdbc = "jdbc:microsoft:sqlserver://btns:1433;DatabaseName=CommunityMedical";
          String sqlUser = "sa";
          String sqlPwd = "btn";
          Connection conn =  null ;
          java.sql.Statement stmt = null ;
          try {
               Class.forName(sqlDriver);
               conn = DriverManager.getConnection(sqlJdbc, sqlUser, sqlPwd);
               stmt = conn.createStatement();
               java.sql.ResultSet rs=stmt.executeQuery("select 1");
               if(rs.next()){
               out.println("ok");
            }
          } catch (Exception e) {
               out.println(e);
          }  finally {
             try { if( stmt != null ) stmt.close() ; } catch( Exception ex ) {}
             try { if( conn != null ) conn.close() ; } catch( Exception ex ) {}
          }
%>
hi TimYates :
-->Do you ever close your Statements and Connections?

i dont't close the Statements and Connections,and this will create  "error establishing socket",and not another case??


thanks!
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks! i will change my code.


   Best Regard!
Good luck!!

:-)