Solved

about "error establishing socket"??

Posted on 2004-10-13
6
295 Views
Last Modified: 2010-04-01
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!
0
Comment
Question by:hgbdelphi
  • 3
  • 3
6 Comments
 

Author Comment

by:hgbdelphi
ID: 12305795
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.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12306031
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 ) {}
          }
%>
0
 

Author Comment

by:hgbdelphi
ID: 12314062
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!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 35

Accepted Solution

by:
TimYates earned 100 total points
ID: 12317235
> i dont't close the Statements and Connections,and this will create  "error establishing socket",and not another case??

Yes, this will cause the problem, as SQLServer will run out of sockets.  You need to close statements and sockets...

You can use a connection pool which will speed up your connection getting (and stop you using too many concurrent connections)

This is how to do it with Tomcat:

http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples-howto.html
0
 

Author Comment

by:hgbdelphi
ID: 12335155
thanks! i will change my code.


   Best Regard!
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12336846
Good luck!!

:-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Struts tiles for layout structure along with Angular JS. 4 152
gZip compression filter 2 125
love6 challenge java 31 129
java operators 3 110
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now