public boolean exportExcel(List lstUser) {
Connection conn =
null;
PreparedStatement stat = null;
try
{
conn = super.getConn();
conn.setAutoCommit(false);//设置手动提交
stat =
conn.prepareStatement("insert into tuser values(?,?)");
User user = new User();
for(int i = 0
;i<lstUser.size();i++){
user = (User)
lstUser.get(i);
stat.setString(1,
user.getUsername());
stat.setInt(2,
user.getAge());
stat.executeUpdate();
if(i==2)
throw new
Exception();
}
conn.commit();//提交
conn.setAutoCommit(true);//设置自动提交
return true;
} catch (Exception e)
{ //当出现异常时
try
{
conn.rollback();//回滚
} catch
(SQLException e1)
{
e1.printStackTrace();
}
e.printStackTrace();
}finally{
super.closeAll(conn,
stat, null);
}
return false;
}