当前位置: 代码迷 >> J2SE >> 下传文件并split后保存到表的有关问题
  详细解决方案

下传文件并split后保存到表的有关问题

热度:7938   发布时间:2013-02-25 21:55:36.0
上传文件并split后保存到表的问题
本身不复杂的一件事,上传后按行读取文件,内容用逗号分隔,split后就存入表,也不需要更多的数据处理。
但是保存时报错:

[WARN ] 121206 11:22:45,093 JDBCExceptionReporter:77 - SQL Error: 0, SQLState: 22001
[ERROR] 121206 11:22:45,093 JDBCExceptionReporter:78 - Data truncation: Data too long for column 'swsystraceaudnum' at row 1

最开始以为是字符编码的问题。但我测试了几次,全用数字,不用汉字也不要字母。最后怀疑应该是读到文件结尾的问题。因为我把赋值的顺序调换一下,也仍然是在最后一个值(5)这里报错。
而且,我打印str4后面的星号没有打印出来。
这样的话,是不是文件结尾符的问题呢?有没有这么个东西?这里要怎么做呢?大神们帮我啊!

下面是日志

line=111,222,333,444,555
str=111,222,333,444,555
[line-0]=111
[line-1]=222
[line-2]=333
[line-3]=444
[line-4]=555
[DEBUG] 121206 11:22:44,953 SQL:102 - select count(*) as col_0_0_ from vip_bank_inputdetail vipbankinp0_ where vipbankinp0_.panval='222' and vipbankinp0_.swsystraceaudnum='444'
detail exist,num=0
*******************
*****str4=555
*******************
id=12511121314
time=555
[DEBUG] 121206 11:22:45,031 SQL:102 - select vipbankinp_.id, vipbankinp_.merchantstype as merchant2_39_, vipbankinp_.panval as panval39_, vipbankinp_.amountoftxn as amountof4_39_, vipbankinp_.swsystraceaudnum as swsystra5_39_, vipbankinp_.timeofoctxn as timeofoc6_39_, vipbankinp_.status as status39_ from vip_bank_inputdetail vipbankinp_ where vipbankinp_.id=?
[DEBUG] 121206 11:22:45,046 SQL:102 - update vip_bank_inputdetail set merchantstype=?, panval=?, amountoftxn=?, swsystraceaudnum=?, timeofoctxn=?, status=? where id=?
[WARN ] 121206 11:22:45,093 JDBCExceptionReporter:77 - SQL Error: 0, SQLState: 22001
[ERROR] 121206 11:22:45,093 JDBCExceptionReporter:78 - Data truncation: Data too long for column 'swsystraceaudnum' at row 1
[ERROR] 121206 11:22:45,109 AbstractFlushingEventListener:301 - Could not synchronize database state with session
org.hibernate.exception.DataException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:77)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:251)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)


下面是代码


File saveFile = null;
if(penvalFile != null){
saveFile = new File(fileName);
if(!saveFile.getParentFile().exists()){
saveFile.getParentFile().mkdirs();
}
FileUtil.copy(penvalFile, saveFile);
}
if(!saveFile.exists()){//上传出错,提示用户重新上传
this.setMsg("上传失败,请重新上传!");
}else{
//2.读取上传后的文件,保存至数据库
BufferedReader  br = null;
String line = null;
String str = null;
VipBankInputDetail vbi = null;
try{
br = new BufferedReader(new FileReader(saveFile), 1024);
while((line= br.readLine()) != null){
System.out.println("line=" + line);
str = new String(line.getBytes("GBK"));
System.out.println("str=" + str);
  相关解决方案