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。
请问数据库是不是有限制连接数目?怎样解决上面的错误?
20 个解决方案
#1
把你获得Connection的代码贴出来
#2
把代码贴上来看看
#3
public Connection useXmlConnection(){
String className="";
String url="";
String username="";
String password="";
File file=new File(this.getClass().getResource(xmlPath).getPath());
SAXReader reader=new SAXReader();
Document document=null;
try {
document = reader.read(file);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
Element root=document.getRootElement();
Iterator iter=root.elementIterator();
Element foo;
while(iter.hasNext()){
foo=(Element)iter.next();
String name=foo.elementText("name");
String value=foo.elementText("value");
if("url".equalsIgnoreCase(name)){
url=value;
}else if("DriverClassName".equalsIgnoreCase(name)){
className=value;
}
else if("userName".equalsIgnoreCase(name)){
username=value;
}
else if("passWord".equalsIgnoreCase(name)){
password=value;
}
}
try {
Class.forName(className).newInstance();
conn=DriverManager.getConnection(url, username, password);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
String className="";
String url="";
String username="";
String password="";
File file=new File(this.getClass().getResource(xmlPath).getPath());
SAXReader reader=new SAXReader();
Document document=null;
try {
document = reader.read(file);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
Element root=document.getRootElement();
Iterator iter=root.elementIterator();
Element foo;
while(iter.hasNext()){
foo=(Element)iter.next();
String name=foo.elementText("name");
String value=foo.elementText("value");
if("url".equalsIgnoreCase(name)){
url=value;
}else if("DriverClassName".equalsIgnoreCase(name)){
className=value;
}
else if("userName".equalsIgnoreCase(name)){
username=value;
}
else if("passWord".equalsIgnoreCase(name)){
password=value;
}
}
try {
Class.forName(className).newInstance();
conn=DriverManager.getConnection(url, username, password);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
#4
对了,以前这句
Class.forName(className).newInstance();
没有加newInstance();我刚加上去的
Class.forName(className).newInstance();
没有加newInstance();我刚加上去的
#5
估计可以支持很多个吧。。。
#6
最近遇到一个问题,用JDBC直接连接数据库,没用连接池,当网站访问量增大时(网上报名),出现下面错误:
-------------------------------------
修改连接数可以直接修改oracle下的dbs目录下init.ora文件,但是不建议这样做,最好使用连接池.
-------------------------------------
修改连接数可以直接修改oracle下的dbs目录下init.ora文件,但是不建议这样做,最好使用连接池.
#7
连完就关,应该还好
#8
友情支持
#9
基本不用JDBC连接数据库~
#10
还是换个连接池吧
#11
不能用连接池,因为后台操作是用的TOMCAT的连接池,他是写死在一个标签里,我不能引用。如果我自己使用一个连接池,就会跟后台那个冲突,具体报的什么错我现在不知道了,反正会出错,所以才改成直接连接的
#12
对了
一个工程能不能连接两个连接池?
一个工程能不能连接两个连接池?
#13
没用连接池 那用的就是数据库的连接数
配置数据库 肯定有配这个的
一个工程用两个连接池没问题
配置数据库 肯定有配这个的
一个工程用两个连接池没问题
#14
conn.close();
#15
连接在另一个方法里关闭了的
#16
UP
#17
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;
}
*********************************************************************************
好像少了这个
finally{
JDBCUtil.closeAll(stmt, rs);
}
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;
}
*********************************************************************************
好像少了这个
finally{
JDBCUtil.closeAll(stmt, rs);
}
#18
Oracle 默认最大连接数是150,可以通过修改init.ora
###########################################
processes=150
###########################################
processes=150
#19
可能是你资源占用太多,在finally里把它关掉。
#20
上面我发那段代码只是获得连接
操作数据库的代码DbUtils.java有关闭连接的方法
public void releaseConnection(){
if(rs!=null){
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(stmt!=null){
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
操作数据库的代码DbUtils.java有关闭连接的方法
public void releaseConnection(){
if(rs!=null){
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(stmt!=null){
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
#21
#1
把你获得Connection的代码贴出来
#2
把代码贴上来看看
#3
public Connection useXmlConnection(){
String className="";
String url="";
String username="";
String password="";
File file=new File(this.getClass().getResource(xmlPath).getPath());
SAXReader reader=new SAXReader();
Document document=null;
try {
document = reader.read(file);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
Element root=document.getRootElement();
Iterator iter=root.elementIterator();
Element foo;
while(iter.hasNext()){
foo=(Element)iter.next();
String name=foo.elementText("name");
String value=foo.elementText("value");
if("url".equalsIgnoreCase(name)){
url=value;
}else if("DriverClassName".equalsIgnoreCase(name)){
className=value;
}
else if("userName".equalsIgnoreCase(name)){
username=value;
}
else if("passWord".equalsIgnoreCase(name)){
password=value;
}
}
try {
Class.forName(className).newInstance();
conn=DriverManager.getConnection(url, username, password);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
String className="";
String url="";
String username="";
String password="";
File file=new File(this.getClass().getResource(xmlPath).getPath());
SAXReader reader=new SAXReader();
Document document=null;
try {
document = reader.read(file);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
Element root=document.getRootElement();
Iterator iter=root.elementIterator();
Element foo;
while(iter.hasNext()){
foo=(Element)iter.next();
String name=foo.elementText("name");
String value=foo.elementText("value");
if("url".equalsIgnoreCase(name)){
url=value;
}else if("DriverClassName".equalsIgnoreCase(name)){
className=value;
}
else if("userName".equalsIgnoreCase(name)){
username=value;
}
else if("passWord".equalsIgnoreCase(name)){
password=value;
}
}
try {
Class.forName(className).newInstance();
conn=DriverManager.getConnection(url, username, password);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
#4
对了,以前这句
Class.forName(className).newInstance();
没有加newInstance();我刚加上去的
Class.forName(className).newInstance();
没有加newInstance();我刚加上去的
#5
估计可以支持很多个吧。。。
#6
最近遇到一个问题,用JDBC直接连接数据库,没用连接池,当网站访问量增大时(网上报名),出现下面错误:
-------------------------------------
修改连接数可以直接修改oracle下的dbs目录下init.ora文件,但是不建议这样做,最好使用连接池.
-------------------------------------
修改连接数可以直接修改oracle下的dbs目录下init.ora文件,但是不建议这样做,最好使用连接池.
#7
连完就关,应该还好
#8
友情支持
#9
基本不用JDBC连接数据库~
#10
还是换个连接池吧
#11
不能用连接池,因为后台操作是用的TOMCAT的连接池,他是写死在一个标签里,我不能引用。如果我自己使用一个连接池,就会跟后台那个冲突,具体报的什么错我现在不知道了,反正会出错,所以才改成直接连接的
#12
对了
一个工程能不能连接两个连接池?
一个工程能不能连接两个连接池?
#13
没用连接池 那用的就是数据库的连接数
配置数据库 肯定有配这个的
一个工程用两个连接池没问题
配置数据库 肯定有配这个的
一个工程用两个连接池没问题
#14
conn.close();
#15
连接在另一个方法里关闭了的
#16
UP
#17
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;
}
*********************************************************************************
好像少了这个
finally{
JDBCUtil.closeAll(stmt, rs);
}
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;
}
*********************************************************************************
好像少了这个
finally{
JDBCUtil.closeAll(stmt, rs);
}
#18
Oracle 默认最大连接数是150,可以通过修改init.ora
###########################################
processes=150
###########################################
processes=150
#19
可能是你资源占用太多,在finally里把它关掉。
#20
上面我发那段代码只是获得连接
操作数据库的代码DbUtils.java有关闭连接的方法
public void releaseConnection(){
if(rs!=null){
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(stmt!=null){
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
操作数据库的代码DbUtils.java有关闭连接的方法
public void releaseConnection(){
if(rs!=null){
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(stmt!=null){
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}