HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: javax.servlet.ServletException: com.mysql.jdbc.CommunicationsException: The driver was unable to create a connection due to an inability to establish the client portion of a socket.This is usually caused by a limit on the number of sockets imposed by the operating system. This limit is usually configurable. For Unix-based platforms, see the manual page for the 'ulimit' command. Kernel or system reconfiguration may also be required.For Windows-based platforms, see Microsoft Knowledge Base Article 196271 (Q196271).
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:532)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:408)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause javax.servlet.ServletException: com.mysql.jdbc.CommunicationsException: The driver was unable to create a connection due to an inability to establish the client portion of a socket.This is usually caused by a limit on the number of sockets imposed by the operating system. This limit is usually configurable. For Unix-based platforms, see the manual page for the 'ulimit' command. Kernel or system reconfiguration may also be required.For Windows-based platforms, see Microsoft Knowledge Base Article 196271 (Q196271).
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:855)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:784)
org.apache.jsp.manager.inser_jsp._jspService(inser_jsp.java:95)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause com.mysql.jdbc.CommunicationsException: The driver was unable to create a connection due to an inability to establish the client portion of a socket.This is usually caused by a limit on the number of sockets imposed by the operating system. This limit is usually configurable. For Unix-based platforms, see the manual page for the 'ulimit' command. Kernel or system reconfiguration may also be required.For Windows-based platforms, see Microsoft Knowledge Base Article 196271 (Q196271).
com.mysql.jdbc.Connection.createNewIO(Connection.java:2814)
com.mysql.jdbc.Connection.<init>(Connection.java:1553)
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
cn.com.util.DataBase.openConnection(DataBase.java:16)
cn.com.util.DataBase.dataUpdates(DataBase.java:106)
cn.com.bean.A_Operation.new_operation(A_Operation.java:22)
org.apache.jsp.manager.inser_jsp._jspService(inser_jsp.java:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.
--------------------------------------------------------------------------------Apache Tomcat/6.0.10
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:532)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:408)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause javax.servlet.ServletException: com.mysql.jdbc.CommunicationsException: The driver was unable to create a connection due to an inability to establish the client portion of a socket.This is usually caused by a limit on the number of sockets imposed by the operating system. This limit is usually configurable. For Unix-based platforms, see the manual page for the 'ulimit' command. Kernel or system reconfiguration may also be required.For Windows-based platforms, see Microsoft Knowledge Base Article 196271 (Q196271).
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:855)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:784)
org.apache.jsp.manager.inser_jsp._jspService(inser_jsp.java:95)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause com.mysql.jdbc.CommunicationsException: The driver was unable to create a connection due to an inability to establish the client portion of a socket.This is usually caused by a limit on the number of sockets imposed by the operating system. This limit is usually configurable. For Unix-based platforms, see the manual page for the 'ulimit' command. Kernel or system reconfiguration may also be required.For Windows-based platforms, see Microsoft Knowledge Base Article 196271 (Q196271).
com.mysql.jdbc.Connection.createNewIO(Connection.java:2814)
com.mysql.jdbc.Connection.<init>(Connection.java:1553)
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
cn.com.util.DataBase.openConnection(DataBase.java:16)
cn.com.util.DataBase.dataUpdates(DataBase.java:106)
cn.com.bean.A_Operation.new_operation(A_Operation.java:22)
org.apache.jsp.manager.inser_jsp._jspService(inser_jsp.java:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.
--------------------------------------------------------------------------------Apache Tomcat/6.0.10
楼主截止到2008-06-21 08:00:02的汇总数据:
注册日期:2008-3-2
上次登录:2008-6-21
发帖数:2 发帖分:40
结贴数:0 结贴分:0
结贴率:0.00 % 结分率:0.00 %
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
异常如下com.mysql.jdbc.CommunicationsException: The driver was unable to create a connection due to an inability to establish the client portion of a socket. This is usually caused by a limit on the number of sockets imposed by the operating system. This limit is usually configurable. For Unix-based platforms, see the manual page for the 'ulimit' command. Kernel or system reconfiguration may also be required. For Windows-based platforms, see Microsoft Knowledge Base Article 196271
发表于:2008-06-21 08:51:517楼 得分:0
引用 4 楼 myooo 的回复:我这个是在插入2000条数据,连续按几下刷新出错的,如何解决
也就是说不连续刷,程序是可以连接到数据库,且可以正常工作的对么? ####################################只能插入三次,第四次出错,也就是说只能插入6000杀数据,然后等一会才能重新插入
连接放在finally里关闭
不要返回ResultSet,封装成list如果你连续插入然后把数据查出来的话,应该是你查询时连接没关闭引起的
String Driver="com.mysql.jdbc.Driver"; //驱动程序
String URL="jdbc:mysql://localhost:3306/db_name"; //连接的URL,db_name为数据库名
String Username="username"; //用户名
String Password="password"; //密码
Class.forName(Driver).new Instance();
Connection con=DriverManager.getConnection(URL,Username,Password);驱动搞错了吧
是不是将原来的 //插入数据
public boolean executeInsert(String insert_SQL) throws Exception {
pstmt = openConnection().prepareStatement(insert_SQL);
try {
pstmt.executeUpdate();
closePreparedStatement();
closeConnection();
return true;
} catch (Exception ex) {
System.err.println(ex.getMessage());
closePreparedStatement();
closeConnection();
return false;
}
}######################################################
改成下面这样子呀
//插入数据
public boolean executeInsert(String insert_SQL) throws Exception {
pstmt = openConnection().prepareStatement(insert_SQL);
try {
pstmt.executeUpdate();
return true;
} catch (Exception ex) { System.err.println(ex.getMessage());
return false;
}
finally
{
closePreparedStatement();
closeConnection(); }
}
我用的是这个包mysql-connector-java-5.0.5-bin.jar
我用的是这个包 mysql-connector-java-5.0.5-bin.jar mysql版本是 mysql-5.0.27
造成问题的原因是不是JDBC驱动有问题!
public boolean executeInsert(String insert_SQL) throws Exception {
pstmt = openConnection().prepareStatement(insert_SQL);
try {
pstmt.executeUpdate();
closePreparedStatement();
closeConnection();
return true;
} catch (Exception ex) {
System.err.println(ex.getMessage());
closePreparedStatement();
closeConnection();
return false;
}
} //更新数据库数据
public boolean executeUpdate(String update_SQL) throws Exception {
pstmt = openConnection().prepareStatement(update_SQL);
try {
pstmt.executeUpdate();
closePreparedStatement();
closeConnection();
return true;
} catch (Exception ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
closePreparedStatement();
closeConnection();
return false;
}
} //返回布尔值,数据存在为真,否则为假
public boolean boolData(String bool_SQL) throws Exception {
pstmt = openConnection().prepareStatement(bool_SQL);
boolean bool = false;
ResultSet rs = null;
try {
rs = pstmt.executeQuery();
if(rs.next()) {
bool = true;
} else {
bool = false;
}
} catch (Exception ex) {
System.err.println("sql_data.executeQuery:" + ex.getMessage());
bool = true;
}
rs.close();
closePreparedStatement();
closeConnection();
return bool;
} //返回记录数
public int getResultCount(String count_SQL) throws Exception {
pstmt = openConnection().prepareStatement(count_SQL);
int icount = 0;
ResultSet rs = null;
try {
rs = pstmt.executeQuery();
while (rs.next()) {
icount = rs.getInt(1);
}
} catch(Exception ex) {
System.err.println("sql_data.executeQuery:" + ex.getMessage());
icount = 0;
}
rs.close();
closePreparedStatement();
closeConnection();
return icount;
}
}
在关闭连接的时候出错了,然后连接没关好。
一次性插入2000条数据,开关数据库连接2000次,你不觉得这样非常浪费吗?
这么高频率的开关数据库连接,不报错才怪了。
强烈建议修改程序,最好是开一次连接,做n次事务。
关闭方法做一个方法写吧。
把关闭方法写在finally{
}里面啊。
package cn.com.util;import java.sql.*;public class DataBase { public Connection conn=null;
public PreparedStatement pstmt; public DataBase()throws Exception { } //打开并返回一个数据库连接
public Connection openConnection() throws Exception {
String url = "jdbc:mysql://localhost:3306/idata?user=root&password=130411";
url += "&useUnicode=true&characterEncoding=UTF-8";
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection(url);
return conn;
} //关闭数据库连接
public void closeConnection() throws Exception {
try {
if(conn != null) {
conn.close();
}
} catch (Exception ex) {
conn.close();
System.out.print(ex.toString());
}
} //关闭PreparedStatement
public void closePreparedStatement() throws Exception {
try {
if(pstmt != null) {
pstmt.close();
}
} catch (Exception ex) {
pstmt.close();
System.out.print(ex.toString());
}
} //返回ResultSet
public ResultSet executeQuery(String m_SQL) {
ResultSet rs = null;
try {
pstmt = openConnection().prepareStatement(m_SQL);
rs = pstmt.executeQuery();
} catch (Exception ex) {
System.err.println("sql_data.executeQuery:" + ex.getMessage());
}
return rs;
} //插入数据
public boolean executeInsert(String insert_SQL) throws Exception {
pstmt = openConnection().prepareStatement(insert_SQL);
try {
pstmt.executeUpdate();
closePreparedStatement();
closeConnection();
return true;
} catch (Exception ex) {
System.err.println(ex.getMessage());
closePreparedStatement();
closeConnection();
return false;
}
} //更新数据库数据
public boolean executeUpdate(String update_SQL) throws Exception {
pstmt = openConnection().prepareStatement(update_SQL);
try {
pstmt.executeUpdate();
closePreparedStatement();
closeConnection();
return true;
} catch (Exception ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
closePreparedStatement();
closeConnection();
return false;
}
} //返回布尔值,数据存在为真,否则为假
public boolean boolData(String bool_SQL) throws Exception {
pstmt = openConnection().prepareStatement(bool_SQL);
boolean bool = false;
ResultSet rs = null;
try {
rs = pstmt.executeQuery();
if(rs.next()) {
bool = true;
} else {
bool = false;
}
} catch (Exception ex) {
System.err.println("sql_data.executeQuery:" + ex.getMessage());
bool = true;
}
rs.close();
closePreparedStatement();
closeConnection();
return bool;
} //返回记录数
public int getResultCount(String count_SQL) throws Exception {
pstmt = openConnection().prepareStatement(count_SQL);
int icount = 0;
ResultSet rs = null;
try {
rs = pstmt.executeQuery();
while (rs.next()) {
icount = rs.getInt(1);
}
} catch(Exception ex) {
System.err.println("sql_data.executeQuery:" + ex.getMessage());
icount = 0;
}
rs.close();
closePreparedStatement();
closeConnection();
return icount;
}
}#################################连接好像都关了呀