在线等,急!用SSH向mysql插入数据的时候报Data too long for...
表为 tbl_xx省_xx类型,每个省份,类型一张表,很多张表,所以采用存储过程方式进行操作。
在用户修改一条记录时候,会备份数据到log表中,在update时候出错,insert into log没问题。
dao:
public void updateMerchant(Merchant m,String province,String type) { Query query = this.getSession().getNamedQuery("updateMerchant"); query.setLong(0, m.getClId()); query.setString(1, m.getClName()); query.setString(2, m.getClCity()); query.setInteger(3, m.getClCategory()); query.setString(4, m.getClDetailaddress()); query.setString(5, m.getClNormaladdress()); query.setString(6, m.getClTelephone()); query.setDouble(7, m.getClLongitude()); query.setDouble(8, m.getClLatitude()); query.setString(9, m.getClTraffic()); query.setString(10, m.getClDescription()); query.setLong(11, m.getClImageid()); query.setInteger(12, m.getClRank()); query.setString(13, province); query.setString(14, type); query.executeUpdate(); }
public String updateMerchant() throws Exception { try { //根据ID所查找出来的商家对象 Merchant merchant = (Merchant) ActionContext.getContext() .getSession().get("merchant"); //省份拼音转换,将省份拼音放入数据路,例如江苏省==jiangsu String provinceSpell = ActionContext.getContext().getSession() .get(province).toString(); //登陆的用户 User user = (User) ActionContext.getContext().getSession() .get("user"); //将省份拼音和商家类型放入session,更改后重新查询 ActionContext.getContext().getSession().put("province", provinceSpell); ActionContext.getContext().getSession().put("bigtype", bigtype); m.setClTime(merchant.getClTime()); //m为struts2 动态封装页面对象 service.updateMerchant(m, provinceSpell, bigtype); //将M表中的数据插入到mlog表中备份 mLog.setClName(merchant.getClName()); mLog.setClCity(merchant.getClCity()); mLog.setClCategory(merchant.getClCategory()); mLog.setClDetailaddress(merchant.getClDetailaddress()); mLog.setClNormaladdress(merchant.getClNormaladdress()); mLog.setClLongitude(merchant.getClLongitude()); mLog.setClLatitude(merchant.getClLatitude()); mLog.setClTraffic(merchant.getClTraffic()); mLog.setClDescription(merchant.getClDescription()); mLog.setClTime(merchant.getClTime()); mLog.setClTelephone(merchant.getClTelephone()); mLog.setClProvince(provinceSpell); mLog.setClType(bigtype); mLog.setClMerchantId(m.getClId()); mLog.setClUserId(user.getClId()); //保存数据至数据库 service.copyMerchantLog(mLog); } catch (Exception e) { e.printStackTrace(); return ERROR; } ActionContext.getContext().getSession().put("msg", "<script>alert('修改成功')</script>"); return SUCCESS; }
DELIMITER $$DROP PROCEDURE IF EXISTS `sp_updatemerchant` $$CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_updatemerchant`(in id bigint(20),in name varchar(45),in city varchar(45),in category int(11),in detailaddress varchar(45),in normaladdress varchar(45),in telephone varchar(45),in longitude double,in latitude double,in traffic text,in description text,in imageid bigint(20),in rank int(11),in province varchar(45),in type VARCHAR(45))BEGINSET @sqltext = concat('update tbl_',province,'_',type,' set cl_name=\'',name,'\', cl_city=\'',city,'\', cl_category=',category,',cl_detailaddress=\'',detailaddress,'\',cl_normaladdress=\'',normaladdress,'\',cl_telephone=\'',telephone,'\',cl_longitude=',longitude,',cl_latitude=',latitude,',cl_traffic=\'',traffic,'\',cl_description=\'',description,'\',cl_imageid=',imageid,',cl_rank=',rank,' where cl_id =',id,';');PREPARE sqlstr from @sqltext;Execute sqlstr;END $$DELIMITER ;
<hibernate-mapping> <class name="com.shockman.merchant.entity.Merchant" table="tbl_merchant" catalog="merchant" dynamic-insert="true"> <id name="clId" type="java.lang.Long"> <column name="cl_id" /> <generator class="assigned" /> </id> <property name="clName" type="java.lang.String"> <column name="cl_name" length="255" /> </property> <property name="clCity" type="java.lang.String"> <column name="cl_city" length="45" /> </property> <property name="clCategory" type="java.lang.Integer"> <column name="cl_category" /> </property> <property name="clDetailaddress" type="java.lang.String"> <column name="cl_detailaddress" /> </property> <property name="clNormaladdress" type="java.lang.String"> <column name="cl_normaladdress" /> </property> <property name="clTelephone" type="java.lang.String"> <column name="cl_telephone" length="45" /> </property> <property name="clLongitude" type="java.lang.Double"> <column name="cl_longitude" precision="22" scale="0" /> </property> <property name="clLatitude" type="java.lang.Double"> <column name="cl_latitude" precision="22" scale="0" /> </property> <property name="clTraffic" type="java.lang.String"> <column name="cl_traffic" length="65535" /> </property> <property name="clDescription" type="java.lang.String"> <column name="cl_description" length="65535" /> </property> <property name="clImageid" type="java.lang.Long"> <column name="cl_imageid" /> </property> <property name="clRank" type="java.lang.Integer"> <column name="cl_rank" /> </property> <property name="clTime" type="java.sql.Timestamp"> <column name="cl_time" length="19" /> </property> </class> <sql-query name="updateMerchant"> {call sp_updatemerchant(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)} <return alias="l" class="com.shockman.merchant.entity.Merchant" /> </sql-query></hibernate-mapping>
org.hibernate.exception.DataException: could not execute native bulk manipulation query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:100) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:198) at org.hibernate.impl.SessionImpl.executeNativeUpdate(SessionImpl.java:1191) at org.hibernate.impl.SQLQueryImpl.executeUpdate(SQLQueryImpl.java:357) at merchant.dao.MerchantDao.updateMerchant(MerchantDao.java:72) at merchant.service.MerchantService.updateMerchant(MerchantService.java:39) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint at at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263) at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) ... ... ...(StrutsPrepareAndExecuteFilter.java:91) Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'cl_name' at row 1 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3595) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2625) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2119) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2415) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2333) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2318) at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102) at org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:189) ... 87 more