`
harryKuo
  • 浏览: 15428 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

奇怪,向mysql插入数据部分会出现Data truncated for column 错误

阅读更多
使用框架:hibernate+spring+webwork+freemark

程序部分:
public String UpInaccExcel() throws Exception
{
message="";
if (!hasPermission(PermConst.INACC_BATCHADD)) {
message = "抱歉,您无该操作的权限!";
return Constant.NOT_AUTHORIZE;
}
if(inaccFile == null)
{
message="请选择要上传的Excel文件";
return INPUT;
}
else
{
try{
  Workbook wb = Workbook.getWorkbook(inaccFile);
  Sheet sheet = wb.getSheet(0);
  //总行数
  int  count  =  sheet.getRows();
  //取出标题
              String a1  =  sheet.getCell( 0 , 0 ).getContents().trim();
              String a2  =  sheet.getCell( 1 , 0 ).getContents().trim();
              String a3  =  sheet.getCell( 2 , 0 ).getContents().trim();
              String a4  =  sheet.getCell( 3 , 0 ).getContents().trim();
              String a5  =  sheet.getCell( 4 , 0 ).getContents().trim();
              String a6  =  sheet.getCell( 5 , 0 ).getContents().trim();
              String a7  =  sheet.getCell( 6 , 0 ).getContents().trim();
              String a8  =  sheet.getCell( 7 , 0 ).getContents().trim();
              String a9  =  sheet.getCell( 8 , 0 ).getContents().trim();
              String a10  =  sheet.getCell( 9 , 0 ).getContents().trim();
             
              if(a1.equals("所在仓库") && a2.equals("品牌")&& a3.equals("产品大类")
              && a4.equals("配件编号")&& a5.equals("配件名称") && a6.equals("配件规格")&& a7.equals("仓位")
              && a8.equals("配件数量")&& a9.equals("配件单价")&& a10.equals("配件金额"))
              {
              for ( int  i  =   1 ;i  <  count;i ++ ){
             
              try{
                      Cell[] cells  =  sheet.getRow(i);
                      System.out.println(cells[ 0 ].getContents()
                               + cells[ 1 ].getContents() + cells[ 2 ].getContents()
                               + cells[ 3 ].getContents() + cells[ 4 ].getContents()
                               + cells[ 5 ].getContents() + cells[ 6 ].getContents()+ "---"+Double.parseDouble(cells[ 9 ].getContents())+"---

-"+StringUtil.MySubstring(cells[ 5 ].getContents(),100));
                String scope = "storageName=?";
              Collection paras = new ArrayList();
              paras.add(cells[ 0 ].getContents());
                      Storage tmpstroage = this.storageService.GetInfo(scope, paras);
                      if(tmpstroage!=null){
                      Inaccessories tempinacc = new Inaccessories();
                      tempinacc.setStorage(tmpstroage);
                      tempinacc.setInBrand(StringUtil.MySubstring(cells[ 1 ].getContents(),50));
                      tempinacc.setInProducts(StringUtil.MySubstring(cells[ 2 ].getContents(),50));
                      tempinacc.setInAccNo(StringUtil.MySubstring(cells[ 3 ].getContents(),50));
                      tempinacc.setInAccName(StringUtil.MySubstring(cells[ 4 ].getContents(),100));
                      tempinacc.setInAccStandards(StringUtil.MySubstring(cells[ 5 ].getContents(),100));
                      tempinacc.setInPhysicsSort(StringUtil.MySubstring(cells[ 6 ].getContents(),400));
                      tempinacc.setInSortNum(Integer.parseInt(cells[ 7 ].getContents().trim()));
                      tempinacc.setInAccPrice(Double.parseDouble(cells[ 8 ].getContents().trim()));
                      tempinacc.setInAmount(Double.parseDouble(cells[ 9 ].getContents().trim()));
                      tempinacc.setInCreateDate(new Date());
                      tempinacc.setInOperator(getSessionAccount().getName());
                      tempinacc.setInSatus(0);
                     this.inaccessoriesService.save(tempinacc);
                 }
                     else
                     {
                  inaccFile=null;
                message="已经成功上传前"+(i-1)+"条数据,第"+i+"的仓库不存在请先添加仓库!";
                ToUrlPath="inAccHistory.do";
                return SUCCESS;
                     }
            }
              catch(Exception ex)
            {
                  inaccFile=null;
                  System.out.print(ex.getMessage());
                message="已经成功上传前"+(i-1)+"条数据,请检查第"+i+"以后的数据是否完整、是否按格式!";
                ToUrlPath="inAccHistory.do";
               
                return SUCCESS;
          
            }
                  }
      wb.close();
      inaccFile=null;
      message="成功上传"+(count-1)+"条数据";
      ToUrlPath="inAccHistory.do";
      return SUCCESS;

              }
              else
              {
      wb.close();
      inaccFile=null;
              message="请检查信息是否按格式。";
  return INPUT;
            
              }
 
}
catch(Exception ex){
inaccFile=null;
message="上传失败!请检查上传的文件是否为excel格式、信息是否完整、是否按格式、且大小是否超过1兆。"+ex.toString();
return INPUT;
}
}
}
                                
插入的excel数据                                     
所在仓库 品牌       产品大类 配件编号  配件名称 配件规格 仓位 配件数量 配件单价 配件金额
超人产品仓 超人小家电 剃须刀 60004 超人剃须刀SA22 旋转式1刀头 前台 1 16.64 76.18
超人产品仓 超人小家电 剃须刀 60002 超人剃须刀SA96 浮动旋转双刀头 前台 2 38.09 76.18
超人产品仓 超人小家电 剃须刀 60005 超人剃须刀SA90 旋转式2刀头   前台 1 41.34 41.34
超人产品仓 超人小家电 剃须刀 60006 超人剃须刀SA851 旋转式3刀头 前台 1 62.14 62.14
超人产品仓 超人小家电 剃须刀 60007 超人剃须刀SA851 浮动式双头 前台 2 64.74 129.48
                                  
                                 
第一,二条数就会出错以下错误.其它数据不会出错这样的错误                               
Hibernate operation: could not insert: [com.equipment.vo.Inaccessories]; uncategorized SQLException for SQL [insert into equipment.inaccessories

(In_SortageID, In_AccNo, In_Brand, In_Products, In_AccName, In_PhysicsSort, In_AccStandards, In_CreateDate, In_SortNum, In_Batch, In_AccPrice, In_Amount,

In_Operator, In_Satus, In_ReviewTime, In_ReviewOperator) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; SQL state [01004]; error code [0]; Data

truncation: Data truncated for column 'In_Amount' at row 1

我试过把配件金额那列的数据都改成76.18都会有这样的问题.其实数据就不会. 不知道为什么,也很奇怪.请问谁遇到过这样的问题,如何解决的.先在这谢过大家啦!

我的In_Amount是类型是double的.数据库里的类型是decimal(10,2)

经查明:
decimal(10,2)对应double时是有问题存在.原因不明.知道的朋友补充一下
我把类型改成double(10,2)时就解决了!


分享到:
评论

相关推荐

    mysql常见错误与标准错误对照表.docx

    13. **错误12651000**: "Data truncated for column '%s' at row %ld",数据因超出列的宽度而被截断。 14. **错误13120A000**: "SELECT in a stored program must have INTO",在存储过程中,SELECT语句必须带有...

    MySQL安全模式和非安全模式实验[参考].pdf

    例如,尝试向`browsertype`列插入非枚举值'`maxthon`'会抛出`Data truncated for column 'browsertype' at row 1`的异常。而插入正确的枚举值和数据类型则会成功。 5. `NO_AUTO_CREATE_USER`和`NO_ENGINE_...

    [python+mysql+csv+vscode]使用python将csv导入mysql(csdn)————程序..pdf

    由于数据量较大,如果采用手动或逐条插入的方式不仅效率低下,而且容易出现错误。因此,我们需要设计一种更为高效且可靠的方案来完成这项任务。 #### 二、技术栈选择 - **Python**:作为当前最热门的编程语言之一...

    MySql超长自动截断实例详解

    然而,在实际项目中,通过JDBC驱动执行相同的SQL语句时,可能会遇到错误提示“Data truncated for column '%s' at row %ld”,这意味着数据被截断,但MySQL认为这是不合法的。这是因为MySQL的行为受到`sql_mode`设置...

    深入分析MySQL数据类型 DECIMAL

    | Note | 1265 | Data truncated for column 'col2' at row 1 | +-------+------+-------------------------------------------+ 1 row in set (0.00 sec) ``` 通过实际操作,我们可以了解到,虽然DECIMAL提供了高...

    Delphi7.1 Update

    If you encounter an empty Help Index tab after installing this update, open the d7.ohi file in the Delphi7Help folder and comment out one or more of the index entries by changing the colon in column ...

Global site tag (gtag.js) - Google Analytics