日期:2014-05-18  浏览次数:20936 次

用JDBC直接连接数据库最多支持多少个连接?
最近遇到一个问题,用JDBC直接连接数据库,没用连接池,当网站访问量增大时(网上报名),出现下面错误:
root   cause  

java.lang.NullPointerException
org.septet.website.newtags.db.DbUtils.getExcuteQuery(DbUtils.java:32)
org.septet.website.struts.action.UserSignUpInfoAction.execute(UserSignUpInfoAction.java:65)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note   The   full   stack   trace   of   the   root   cause   is   available   in   the   Apache   Tomcat/5.5.7   logs.


我想可能是获得的连接为空,报的这个错,但每次操作完成后,我都关了连接的。
数据库为ORACLE。
请问数据库是不是有限制连接数目?怎样解决上面的错误?

------解决方案--------------------
最近遇到一个问题,用JDBC直接连接数据库,没用连接池,当网站访问量增大时(网上报名),出现下面错误:
-------------------------------------
修改连接数可以直接修改oracle下的dbs目录下init.ora文件,但是不建议这样做,最好使用连接池.
------解决方案--------------------
没用连接池 那用的就是数据库的连接数
配置数据库 肯定有配这个的
一个工程用两个连接池没问题
------解决方案--------------------
public List selectTanCde(TanCdeEntDAOData data) throws DAOException{
if (log.isTraceEnabled()) {
log.trace( "entering TanCdeEntDAO.selectTanCde() ");
}
String readSql = getSelectTanCdeSql(data);
List ret = new ArrayList();
PreparedStatement stmt = null;
ResultSet rs = null;
try {
String realSql = rdbmsStrategy.convertSelectSql(readSql, TanCdeEntDAO.class, "selectTanCde ");
if (log.isDebugEnabled()) {
log.debug(realSql);
}
stmt = getConnection().prepareStatement(realSql);
JDBCUtil.setString(stmt, 1, data.getTAN_CDE(), rdbmsStrategy);
JDBCUtil.setString(stmt, 2, data.getCOR_CDE(), rdbmsStrategy);
long startTime = 0;
if (log.isInfoEnabled()) {
startTime = System.currentTimeMillis();
}
rs = stmt.executeQuery();
if (log.isInfoEnabled()) {
long finishTime = System.currentTimeMillis();
log.info( "elapsed time: " + (finishTime - startTime) + "ms ");
}

while (rs.next()) {
TanCdeEntDAOData listElement = new TanCdeEntDAOData();
listElement.setTAN_NAM(JDBCUtil.getString(rs, 1, rdbmsStrategy));
ret.add(listElement);
}
if (log.isDebugEnabled()) {
log.debug( "selectTanCde: result count: " + ret.size());
}
} catch (SQLException ex) {
throw new DAOException( "SQLException occured. ", ex);
} finally{
JDBCUtil.closeAll(stmt, rs);
}
if (log.isTraceEnabled()) {
log.trace( "exiting TanCdeEntDAO.selectTanCde() ");
}
return ret;
}
**************************************************************