[Mono-list] Batch inserts with ADO.NET

Cory Nelson phrosty@gmail.com
Sun, 23 May 2004 13:08:46 -0700


I'm not sure how DB2 works but I had the same issue with MySQL.  I
created a simple class that creates insert commands like "insert into
<table> values(value1),(value2),(value3)" and flushed the buffer every
200 or so commands.  It gave an average 10x speed up.

On Sun, 23 May 2004 13:52:15 +0200, Fredrik Hedberg
<fredrik.hedberg@hedbergs.com> wrote:
>=20
> Hi,
>=20
> Par example:
>=20
> command.Text =3D "INSER INTO ...";
> command.Prepare();
>=20
> for (int i =3D 0; i < 10000; i++)
> {
>        // Add some parameter data
>        command.executeNonQuery();
> }
>=20
> The problem is, this still executes queries and checks results from the
> database engine (in my case over the network) for each and every insert.
> This slows the process considerably and while the JDBC add- and
> executeBatch method below does about 80000 inserts per second, code like
> the above snippet only does about 4000 with my current setup.
>=20
> Thanks for you input.
>=20
> /Fred
>=20
>=20
> On Sun, 2004-05-23 at 13:34, Carlos Guzm=E1n =C1lvarez wrote:
> > Hello:
> >
> > >PreparedStatement statement =3D connection.prepareStatement("INSERT
> > >INTO....");
> > >
> > >            for (int i =3D 0; i < 1000; i++)
> > >            {
> > >                    statement.setInt(1,rand.nextInt());
> > >                    statement.addBatch();
> > >            }
> > >            statement.executeBatch();
> > >
> > Maybe you can use parametrized querys and the
> > XxCommand.Prepare method ??
> >
> >
> >
> >
> > --
> > Best regards
> >
> > Carlos Guzm=E1n =C1lvarez
> > Vigo-Spain
> > _______________________________________________
> > Mono-list maillist  -  Mono-list@lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/mono-list
>=20
> _______________________________________________
> Mono-list maillist  -  Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>