Spring 更新表后无法理解异常

Spring 更新表后无法理解异常,spring,hibernate,Spring,Hibernate,已使用Micro soft SQL Server 2008请使用executeUpdate方法而不是使用executeQuery执行更新操作 queryUpdate="UPDATE cctvcamera SET police_station_name='" +list.get(0)+"', url='"+pojo.getUrl()+"',latitude=" +pojo.getLatitude()+",longitude="

已使用Micro soft SQL Server 2008

请使用executeUpdate方法而不是使用executeQuery执行更新操作

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();

                }


            });

在代码中,您正在调用
query.list()
,如果要在数据库上运行select查询,此方法非常有用

将其替换为执行更新,如下所示:

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

谢谢你的回复

我得到了解决方案,我用下面的代码替换了我的旧代码

getHibernateTemplateDCRMS().bulkUpdate(queryUpdate)


//其中queryUpdate是查询字符串

我猜表cctvcamera中没有cameraid=2;发布CameraDetailsDaoImpl.java:119的代码在您获得此异常时显示代码?表中有cameraid=2
com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.
@Override
public Object doInHibernate(Session session) throws HibernateException, SQLException {

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