Results 1 to 4 of 4

Thread: Fast insert record into MySql

  1. #1
    Join Date
    Mar 2009
    Location
    Gansu,China
    Posts
    188
    Qt products
    Qt4
    Platforms
    Windows

    Default Fast insert record into MySql

    I have many records,If I use "Insert(...)" in for(int i=0;i<n;i++),I find that it is very slow,how to insert many records into Mysql fast?

  2. #2
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: Fast insert record into MySql

    You can use transaction.

    Qt Code:
    1. dbConnection.transaction();
    2.  
    3. for(int i=0;i<n;i++)
    4. {
    5. // insert record here
    6. }
    7.  
    8. dbConnection.commit();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Fast insert record into MySql

    transactions are the best way, but if your DBS doesn't support them, then you (maybe) can gain speed by joining all inserts and only execute one INSERT statement.

  4. The following user says thank you to Lykurg for this useful post:

    saa7_go (15th July 2010)

  5. #4
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: Fast insert record into MySql

    Quote Originally Posted by Lykurg View Post
    transactions are the best way, but if your DBS doesn't support them, then you (maybe) can gain speed by joining all inserts and only execute one INSERT statement.
    Yes, you are right. I suggest weixj2003ld to use transaction because he/she uses mysql database. But, thanks for your information.
    Last edited by saa7_go; 15th July 2010 at 09:10. Reason: spelling corrections

Similar Threads

  1. Replies: 2
    Last Post: 17th February 2010, 14:32
  2. unable to insert into mysql table
    By mohanakrishnan in forum Newbie
    Replies: 4
    Last Post: 5th December 2009, 05:02
  3. INSERT query with MySQL problem
    By timmyg in forum Qt Programming
    Replies: 10
    Last Post: 20th March 2008, 21:52
  4. MYSQL insert
    By allensr in forum Newbie
    Replies: 4
    Last Post: 14th August 2006, 16:55
  5. Replies: 7
    Last Post: 12th August 2006, 15:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.