回复人: RedFire(丹焰) ( ) 信誉:100 2002-11-10 20:16:49 得分:0
不应该直接使用连接池的功能,应该在底层的连接上再封装一层,这样申请了连接而没有释放连接的操作很快就能跟踪到了。
________________________________
举个例子吧
不应该直接使用连接池的功能,应该在底层的连接上再封装一层,这样申请了连接而没有释放连接的操作很快就能跟踪到了。
________________________________
举个例子吧
我用的配置是Tomcat4.0.4 + MSSQLSERVER7
2. do not use session bean as simple query methods
3. as for the BMP/CMP, use as least as possible if you are not working with applet/ejb model or somegthing alike.(suggestion from sun)
4. small and often used table should be transfered to arraylist or something else and hang in memory
Tomcat时常死掉,有引用数据库bean的jsp页面打不开,其它页面正常,有时Tomcat会崩溃, 典型的jsp页面如下面的goods.jsp
,可能是数据库连接有问题,但无法打开jsp页面时,打开sql server的企业管理器,能查询数据库,未发现锁定进程,每天要死上两三次,请指点迷津,不胜感激。db.javaimport java.io.*;
import java.sql.*;
//*************************************************************//
public class db
{Connection con = null;
ResultSet rs = null;
Statement stm = null;
String sDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConStr = "jdbc:odbc:db";
String sUID="sa",sPWD="";
//**********************************************************//
public db()
{try
{Class.forName(sDriver);
con = DriverManager.getConnection(sConStr,sUID,sPWD);
stm = con.createStatement();
}
catch(Exception ex)
{System.err.println("\nforName:"+ex.getMessage());}
}
//**********************************************************//
public void close()
{try
{if(rs!=null)
{rs.close();
rs=null;
}
if(stm!=null)
{stm.close();
stm=null;
}
if(con!=null)
{con.close();
con=null;
}
}
catch(SQLException ex)
{System.err.println(ex.getMessage());
}
}
//**********************************************************//
public ResultSet executeQuery(String sql)
{try
{if(stm==null)
return null;
rs = stm.executeQuery(sql);
return rs;
}
catch(SQLException ex)
{System.err.println("\nexecuteQuery:"+ex.getMessage()+" SQL Syntax:"+sql);
return null;
}
}
//**********************************************************//
public boolean executeUpdate(String sql)
{
try
{if(stm==null)
return false;
stm.executeUpdate(sql);
}
catch(SQLException ex)
{System.err.println("\nexecuteUpdate:"+ex.getMessage()+" SQL Syntax:"+sql);
return false;
}
return true;
}
//**********************************************************//
public void setAutoCommit(boolean bAutoCommit)
{try
{con.setAutoCommit(bAutoCommit);
}
catch(SQLException ex)
{System.err.println("\nsetAutoCommit:"+ex.getMessage());
}
}
//**********************************************************//
public void commit()
{try
{con.commit();
}
catch(SQLException ex)
{System.err.println("\ncommit:"+ex.getMessage());
}
}
//**********************************************************//
public void rollback()
{try
{con.rollback();
}
catch(SQLException ex)
{System.err.println("\nrollback:"+ex.getMessage());
}
}
} goods.jsp<%@page contentType = "text/html;charset=gb2312" %>
<%@ page import="java.io.*,java.sql.*,java.util.*"%>
<%@ page session="true"%>
<jsp:useBean id="db" class="com.db" scope="page"/><%
ResultSet rs=null;
String sSql,sId,sCategory,sRet;
sId=request.getParameter("id");
if(sId==null || sId.equals("")){
db.close();
error("参数不足!",out);
return;
}
sSql="select id,name,unit,purchase_price,price,re,sts ";
sSql+=" from goods where id="+sId;
rs=db.executeQuery(sSql);
if(rs==null){
db.close();
error("数据库操作错误!",out);
return;
}
if(!rs.next()){
db.close();
error("未检索到相应信息!",out);
return;
}
%>
<body>
<form name=frmMain method=POST>
<input type=hidden name=id value="<%=sId%>">
<table border="0" cellPadding="0" cellSpacing="0" width="550" >
<tr>
<td height="30" vAlign="center" width="150" align=right><font size="2" color="#000000">物品名称:</font></td>
<td height="30" vAlign="center" colspan="4">
<input type=text class=text name=name size=50 value="<%out.print(rs.getString("name"));%>">
</td>
</tr>
<tr>
<td height="30" vAlign="center" width="150" align=right><font size="2" color="#000000">物品单位:</font></td>
<td height="30" vAlign="center" colspan="4">
<input type=text class=text name=unit size=50 value="<%out.print(rs.getString("unit"));%>">
</td>
</tr>
<tr>
<td height="30" vAlign="center" width="150" align=right><font size="2" color="#000000">进货价格:</font></td>
<td height="30" vAlign="center" colspan="4">
<input type=text class=text name=purchase_price size=50 value="<%out.print(rs.getString("purchase_price"));%>">
</td>
</tr>
<tr>
<td height="30" vAlign="center" width="150" align=right><font size="2" color="#000000">销售价格:</font></td>
<td height="30" vAlign="center" colspan="4">
<input type=text class=text name=price size=50 value="<%out.print(rs.getString("price"));%>">
</td>
</tr>
<tr>
<td height="30" vAlign="center" width="150" align=right><font size="2" color="#000000">备注:</font></td>
<td height="30" vAlign="center" colspan="4">
<input type=text class=text name=re size=50 value="<%out.print(rs.getString("re"));%>">
</td>
</tr>
<tr vAlign="bottom">
<td></td>
<td colSpan="5" height="35" align=right>
<a href='javascript:window.close();'><img src='../img/close_window.gif' border=0></a>
</td>
</tr>
</table>
</form> <% db.close();%>