分类目录归档:JAVA

JAVA

Spring 批量执行语句

   使用Spring ScriptUtils 批量执行Sql语句,如批量执行update table1 set status=0, dprice=55 where id in (9600980);insert into table1 (dprice,status) values(46,0),(55,1);这两条语句。

方法

 public void executeSqlScript(Connection connection,StringBuffer sql)throws SQLException{ try {
			 connection.setAutoCommit(false);//设置为手工提交模式  ScriptUtils.executeSqlScript(connection, new ByteArrayResource(sql.toString().getBytes()));
			 connection.commit();//提交事务  } catch (SQLException e) {
			connection.rollback();
		}finally{
			connection.close();
		}
	 }

Spring 4 MVC and Websockets – No suitable default RequestUpgradeStrategy

                     Spring 4 MVC and Websockets – No suitable default RequestUpgradeStrategy

出错解决方法:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name

‘org.springframework.web.socket.server.support.DefaultHandshakeHandler#0’: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.web.socket.server.support.DefaultHandshakeHandler]: Constructor threw exception; nested exception is java.lang.IllegalStateException: No suitable default RequestUpgradeStrategy found

升级tomcate的版本,解决问题。

Hibernate实体关联查询方法

            在项目中经常要多个实体中查询数据,下面使用Hibernate实体关联查询方法:

DetachedCriteria criteria =DetachedCriteria .forClass(Org.class);
DetachedCriteria staffCeiteria = DetachedCriteria.forClass(Staff.class);
staffCeiteria.setProjection(Property.forName("id"));
staffCeiteria.add(Restrictions.ilike("name",createName,MatchMode.ANYWHERE));
criteria.add(Property.forName("created").in(staffCeiteria));