gpt4 book ai didi

java - Spring MVC 堆栈溢出错误 - 尝试从数据库获取数据

转载 作者:行者123 更新时间:2023-12-02 07:03:20 29 4
gpt4 key购买 nike

我有一个插入数据库的表单,但是在执行插入之前,我会检查是否存在现有记录。我无法插入记录,并且收到 StackOverflow 错误。

有人可以告诉我导致此错误的原因以及我可以采取哪些措施来消除它吗?如果我删除检查 hasRecords 代码执行正常。这几乎就像代码此时不想访问数据库一样。我创建了不同类型的函数来执行他在此处检查记录,但此时我不断收到相同的错误 StackOverflow

代码

com.crimetrack.service.MonitoringManager.getMonitoringStDate(MonitoringManager.java:60)

public String getMonitoringStDate(Integer crimeRecNo,
Integer socialSecurityNumber) throws Exception {

return this.getMonitoringStDate(crimeRecNo, socialSecurityNumber);
}

用于 getMonitoringStDate 的 DAO

public String getMonitoringStDate(Integer crimeRecNo, Integer socialSecurityNumber){

//select the minimum start date in event there is several records although this will not be allowed
String sql = "select IFNULL(min(monitoringStDate),'0') as monitoringStDate from tblmonitoring where crimeRecNo = ? and socialSecurityNumber = ?";

String monitoringStDate = (String)getJdbcTemplate().queryForObject(sql, new Object[]{crimeRecNo,socialSecurityNumber}, String.class);

return monitoringStDate;
}

我还注册了以下监听器:

听众

 <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

代码

DAO

public boolean hasMonitoringRecord(Integer crimeRecNo, Integer socialSecurityNumber){

//select a count of monitoring records there should be only one monitoring record
String sql = "select count(*) as monitoringStDate from tblmonitoring where crimeRecNo = ? and socialSecurityNumber = ?";

Integer count = (Integer)getJdbcTemplate().queryForObject(sql, new Object[]{crimeRecNo,socialSecurityNumber}, Integer.class);

if(count > 0 ){

return true;
}else{
return false;
}
}

Controller

if(result.hasErrors()){

myMonitoringTypeList.put("monitoringTypeList",this.monitoringTypeManager.getListOfMonitoringType());
model.addAttribute("icon", "ui-icon ui-icon-circle-close");
model.addAttribute("results", "Error: Unable to Save Record!");
model.addAttribute("monitoringType",myMonitoringTypeList);
model.addAttribute("monitoring",monitoring);
model.addAttribute("records", session.getAttribute("records"));
model.addAttribute("crimeRecNo",session.getAttribute("crimeRecNo"));


//return the user to the page they were on initially not the first page but the one with the error
return new ModelAndView("monitoringList","page",session.getAttribute("page"));
}else{

int crimeRecNo = monitoring.getCrimeRecNo();
int socialSecurityNumber = monitoring.getSocialSecurityNumber();

logger.info("No errors going to process records");
logger.info("CrimeRecNo is " + monitoring.getCrimeRecNo());
logger.info("SocialSecurity Number is " + monitoring.getSocialSecurityNumber());
//check if a record already exists. if one exist do an update else do an insert
//to check if the record exists we can simply get the start date
String dbMonitoringStDate = monitoringManager.getMonitoringStDate(crimeRecNo,socialSecurityNumber);

logger.info("The dbMonitoringStDate is " + dbMonitoringStDate);

if(monitoringManager.hasMonitoringRecord(crimeRecNo, socialSecurityNumber)){
logger.info("Has monitoring record");
//do an update

monitoringManager.updateMonitoringRecord(monitoring);
model.addAttribute("icon", "ui-icon ui-icon-circle-check");
model.addAttribute("results", "Record Was Updated");
}else {
logger.info("Does not have monitoring record");
//do an insert
monitoringManager.saveMonitoringRecord(monitoring);
model.addAttribute("icon", "ui-icon ui-icon-circle-check");
model.addAttribute("results", "Record Was Saved");
}

错误

7035 [http-bio-8084-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet  - Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@6f138f45
7035 [http-bio-8084-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet - Could not complete request
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.StackOverflowError
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:972)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.StackOverflowError
at com.crimetrack.service.MonitoringManager.getMonitoringStDate(MonitoringManager.java:60)
at com.crimetrack.service.MonitoringManager.getMonitoringStDate(MonitoringManager.java:60)
at com.crimetrack.service.MonitoringManager.getMonitoringStDate(MonitoringManager.java:60)
at com.crimetrack.service.MonitoringManager.getMonitoringStDate(MonitoringManager.java:60)
at com.crimetrack.service.MonitoringManager.getMonitoringStDate(MonitoringManager.java:60)

最佳答案

查看你的方法定义:

public String getMonitoringStDate(Integer crimeRecNo,
Integer socialSecurityNumber) throws Exception {
return this.getMonitoringStDate(crimeRecNo, socialSecurityNumber);
}

该方法唯一做的事情就是调用自身。显然,你有一个无限递归循环。

关于java - Spring MVC 堆栈溢出错误 - 尝试从数据库获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16379291/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com