java使用PreparedStatement的addBatch批量提交数据到mysql

来源:互联网 发布:tcl网络电视怎么开机 编辑:程序博客网 时间:2024/05/29 04:35
/**
     * 批量导入数据
     * @param listInsert
     * @throws SQLException
     */
    public void insertList(List<Device> listInsert) throws SQLException
    {
        @SuppressWarnings("deprecation")
        PreparedStatement ps = getSession().connection().prepareStatement("insert into uhome_device("
                + "dev_reg_flag, dev_model_code, dev_mac) "
                + "values(?,?,?)");
        for (Device device:listInsert)
        {
            ps.setObject(1, device.getRegFlag());
            ps.setObject(2, device.getModelCode());
            ps.setObject(3, device.getMac());
           );
            
            ps.addBatch();
        
        }
        ps.executeBatch();
    }
0 0