/ / Nie można zrozumieć wyjątku po aktualizacji tabeli [duplicate] - spring, hibernate

Nie można zrozumieć wyjątku po aktualizacji tabeli [duplicate] - spring, hibernate

27-Apr 13:21:35 INFO  CameraDetailsDaoImpl [] - org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not execute query; uncategorized SQLException for SQL [UPDATE cctvcamera SET police_station_name="T T Nagar  Police Station", url="", latitude=23.23528492, longitude=77.40121292, junction_name="Top N Town New Market Point",police_station_id=17 WHERE cameraid=2]; SQL state [null]; error code [0]; The statement did not return a result set.; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.
27-Apr 13:21:35 ERROR CameraDetailsDaoImpl [] - updateAlertDetails()
java.lang.NullPointerException
at org.trinity.admin.dao.cameramanagement.CameraDetailsDaoImpl.updateCameraDetails(CameraDetailsDaoImpl.java:119)
at org.trinity.admin.service.cameramanagement.CameraSerivce.updateCameraDetails(CameraSerivce.java:33)
at org.trinity.admin.service.cameramanagement.CameraSerivce$$FastClassByCGLIB$$4a96f69.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:617)
at org.trinity.admin.service.cameramanagement.CameraSerivce$$EnhancerByCGLIB$$8389c032_2.updateCameraDetails(<generated>)
at org.trinity.admin.controller.cameramanagement.CameraManagementController.updateCameraDetails(CameraManagementController.java:148)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

mój kod:

queryUpdate="UPDATE cctvcamera SET police_station_name=""
+list.get(0)+"", url=""+pojo.getUrl()+"",latitude="
+pojo.getLatitude()+",longitude="
+pojo.getLongitude()+", junction_name=""
+pojo.getJunctionName()+"", police_station_id="
+pojo.getPoliceStationName()
+" WHERE cameraid="+pojo.getCameraid()+"";

try {
list1=getHibernateTemplateDCRMS().executeFind(new HibernateCallback() {

@Override
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query q=session.createSQLQuery(queryUpdate);
return q.list();

}


});

Użyty mikro soft SQL Server 2008

Odpowiedzi:

1 dla odpowiedzi № 1

Użyj metody executeUpdate zamiast użyć executeQuery, aby wykonać operację aktualizacji;

com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.

1 dla odpowiedzi nr 2

W twoim kodzie dzwonisz query.list(), ta metoda jest przydatna, jeśli chcesz uruchamiać wybrane zapytania w bazie danych.

Zastąp go executeUpdate lubię to:

@Override
public Object doInHibernate(Session session) throws HibernateException, SQLException {

Query q=session.createSQLQuery(queryUpdate);
return q.executeUpdate();
}

1 dla odpowiedzi nr 3

Dzięki za odpowiedzi.

Mam rozwiązanie, zastąpiłem mój stary kod dowcipny po kodzie

getHibernateTemplateDCRMS (). bulkUpdate (queryUpdate);

// gdzie queryUpdate jest ciągiem zapytania