永发信息网

Java中SSH项目增加异常.在线等答案

答案:2  悬赏:0  手机版
解决时间 2021-05-25 18:23

这是错误信息.
org.springframework.dao.DataIntegrityViolationException: Hibernate operation: could not insert: [po.Car]; SQL [insert into test.dbo.car (carid, carname, cargg, carcc, carcj, id) values (?, ?, ?, ?, ?, ?)]; [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]将截断字符串或二进制数据。; nested exception is java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]将截断字符串或二进制数据。
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]将截断字符串或二进制数据。
 at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
 at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
 at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
 at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
 at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
 at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
 at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
 at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
 at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
 at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source)
 at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
 at com.microsoft.jdbc.base.BaseStatement.executeUpdateInternal(Unknown Source)
 at com.microsoft.jdbc.base.BasePreparedStatement.executeUpdate(Unknown Source)
 at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)
 at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
 at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2062)
 at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2427)
 at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
 at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
 at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
 at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
 at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
 at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
 at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
 at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:394)
 at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:367)
 at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:614)
 at dao.imp.CarDAOImp.save(CarDAOImp.java:31)
 at service.imp.ResaveServiceImp.initDB(ResaveServiceImp.java:91)
 at struts.action.fileAction.execute(fileAction.java:39)
 at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
 at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
 at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
 at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
 at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
 at java.lang.Thread.run(Thread.java:619)

 

 

这是源码:

package service.imp;

import java.io.File;
import java.io.FileInputStream;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import po.Car;
import service.ResaveService;
import dao.ICarDAO;

public class ResaveServiceImp implements ResaveService {

 private ICarDAO cardao;

 public void setCardao(ICarDAO cardao) {
  this.cardao = cardao;
 }

 public void initDB(String fileAndName) {

  StringBuffer stringBuf = new StringBuffer();
  try {
   FileInputStream fis = new FileInputStream(new File(fileAndName));
   HSSFWorkbook xlsbook = new HSSFWorkbook(fis);
   int sheetNum = xlsbook.getNumberOfSheets();
   System.out.println(sheetNum);

   for (int i = 0; i < sheetNum; i++) {
    // ��ͷԪ��
    if (i == 0) {

    } else {
     HSSFSheet sheet = xlsbook.getSheetAt(i);

     int rowNum = sheet.getLastRowNum();

     for (int j = 0; j < rowNum; j++) {
      if (j != 0) {

       Car car = new Car();
       HSSFRow row = sheet.getRow(j);
       if (row != null) {

        int cellNum = row.getLastCellNum();
        String var = "";
        for (int k = 0; k <= cellNum; k++) {
         if (k < cellNum) {
          if (row.getCell(k) != null) {
           var = row.getCell(k).toString();
          } else {
           var = "" + "\t";
          }
         } else {
          if (row.getCell(k) != null) {
           var = row.getCell(k).toString();
          } else {
           var = " ";
          }
         }
         if (k == 1) {
          car.setCarid(var);
         } else if (k == 2) {
          car.setCarname(var);
         } else if (k == 3) {
          car.setCargg(var);
         } else if (k == 4) {
          car.setCarcc(var);
          
         }else if(k==5){
          String carrString = car.getCarcc();
          System.out.println(carrString);
          if(carrString!=null&&!carrString.equals("")){
           Double double1 = Double.parseDouble(carrString);
           String strr = (double1*1.2*1.17)+"";
           String str = strr.toString();
           str = str.substring(0,str.indexOf(".")+2);
           car.setCarcj(str);
          }
          else{
           
           car.setCarcj(" "); 
          }
         }
         // System.out.println(var);
        }
       }
       cardao.save(car);
       System.out.println(j + "..>" + car.getCarid()
         + "///" + car.getCarname() + "///"
         + car.getCargg() + "///" + car.getCarcc()
         + "///" + car.getCarcj());
      }
     }
    }
   }
  } catch (Exception e) {
   e.printStackTrace();
  }

 }

 public List findByProperty(String carid, String carname) {
  List list = cardao.findByProperty(carid, carname);
  return list;
 }

}

最佳答案
截断字符串或二进制数据 就是报的你录入的数据大于你数据库中定义的数据大小。所以你在数据库中改一下你的数据大小就行了。
全部回答
是不是你存储的文件大小超出来你数据库字段的大小
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
前进区佳木斯中国邮政(南岗邮政支局)我想知道
表达悔恨自责的的句子,悔恨自己让女人流泪的
松滋市荆州松滋市人民法院新江口法庭在哪里啊
1、使代数式x-3分之x+3除以x-4分之x+2有意义
石峰区株洲中国联通这个地址怎么能查询到,着
如何买别墅,燃气壁挂炉取暖效果好不好
谁能帮我设计一个杨平平的艺术签名啊 我会非
跪求一份检讨书 本人大三军校生 因多次没有参
天龙客服老打不通怎么滴··
火车离开A站10km后,以55km/h的平均速度前进了
孟州市焦作孟州市人民法院诉讼服务中心这个地
悦家便利店怎么去啊,有知道地址的么
扶沟县周口醉美江西瓦罐小吃(扶沟店)在什么地
英语翻译1我认为动物不应该住在动物园里.2.这
浏阳市长沙锦玉商务宾馆(豪兴街)哪位知道具体
推荐资讯
隆回县邵阳隆回县校外教育中心在哪里啊,我有
我是六月二十二来的月经到现在,昨天去检查都
组装一台玩主流游戏电脑价钱在2000一2500:显
华慧学校我想知道这个在什么地方
移动手机冲QB 为什么显示我的号码被限制拨入
为什么工行网银登陆时摁一下键会出现两个**比
一个人可以带几只宠物
为什么点卷不能买永久性的物品
魔兽猎人进:
如何点亮更多的QQ图标.?
浙江省台州市09-10学年高二下学期期末质量评
现代汽车的标志是H还是N
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?