Ibatis oracle 插入数据

public class UserDao
{
    protected SqlMapClient sqlMap = IBatisUtil.getSqlMapInstance();
    private Log logger = LogFactory.getLog(UserDao.class);
    
    public List<UserBean> queryAll(UserBean qryBean) throws SQLException
    {
        try {
            sqlMap.startTransaction();
            List list = sqlMap.queryForList("User.queryAll", qryBean.getId());
            sqlMap.commitTransaction();
            return list;
        } catch (Exception e) {
            logger.error(e.getMessage());
        } finally {
            sqlMap.endTransaction();
        }
        return new ArrayList();
    }
    
    public int insert(UserBean insertBean) throws SQLException
    {
        try
        {
            sqlMap.startTransaction();
            Object ret = sqlMap.insert("User.insert", insertBean);
            sqlMap.commitTransaction();
        } 
        catch (Exception e)
        {
            logger.error(e.getMessage());
        }
        finally
        {
            sqlMap.endTransaction();
        }
        
        return 0;
    }
    
    public static void main(String [] agrs) throws Exception
    {
        Date startTime = new Date();
        System.out.print("执行开始:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(startTime));
        
        UserDao dao = new UserDao();
        
        /* 测试查询
        UserBean qryBean = new UserBean();
        qryBean.setId("1");
        List listUser = dao.queryAll(qryBean);
        System.out.print(123);
        */
        
        /* 测试插入 */
        UserBean insertBean = null;
        for(long i=0; i<999999; i++)
        {
            insertBean = new UserBean();
            insertBean.setId(String.valueOf(i));
            insertBean.setName("name" + i);
            insertBean.setPassword("pwd_" + i);
            dao.insert(insertBean);
        }
        Date endTime = new Date();
        System.out.print("执行结束:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(endTime));
        System.out.print("执行耗时:" + ((endTime.getTime() - startTime.getTime()) / 1000 ) + "秒");
    }
}

 执行结束:2009-11-19 10:04:22执行耗时:3222秒

 

  
                            

你可能感兴趣的:(DAO,oracle,ibatis)