这是错误信息.
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;
}
}