日期:2014-05-18  浏览次数:20676 次

把文本文件导入到数据库的问题,高手请进,在线等,谢谢!
Connection   con   =   null;
ResultSet   rs   =   null;
Statement   smt   =   null;

try
{
          con   =   ConnectionManager.getConnection();
          con.setAutoCommit(false); //   禁止自动提交,设置回滚点

//   将用户上行记录存入userinput表中

String   sql= "insert   into   userinput   from   "   +   file   +   "   with   (fieldterminator= ', ',rowterminator= '\n ') ";
                                                                       
smt.executeUpdate(sql);
con.close();con=null;
}
catch(Exception   e)
{

try {if(smt!=null)   smt.close();}catch(SQLException   sqle){}
try {if(con!=null)   con.close();}catch(SQLException   sqle){}

}

------解决方案--------------------
是在con.close()前执行con.commit();
------解决方案--------------------
你用什么开发工具 ?
eclipse.exe都有自带的断点插件
------解决方案--------------------
try{
con.setAutoCommit(false)
执行sql语句
然后要con.commit();
}catch(SQLException e){
con.rollback();
}