Results 1 to 4 of 4
  1. #1
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default How to insert large data into database using one insert query

    hi,iam working with JDBC . I face a sitution like this,

    Statement stmt=con.createStatement();
    -------
    for(int i=0;i<1000;i++)
    {
    stmt.executeUpdate("insert into Sample.sampletable(col1,col2,col3) values(value1i,value2i,value3i)";
    );
    -----
    }
    -----
    'con' is Connection object,I am not inserting same values each time for three columns that means value1,value2,value3 changes with each iteration.

    This code takes numerous amount of time ,because 1000 times
    "stmt.executeUpdate(query)" should communicate with database.

    Now I want a alternative for above code in such a way that all values should be inserted with a insertion query that executes only once.
    please help me.

  2. #2
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    if you're using mysql as your database, i recommend using a load data file. i don't know if other databases have an equivalent.

    MySQL :: MySQL 5.1 Reference Manual :: 12.2.6 LOAD DATA INFILE Syntax

  3. #3
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    thank u,but iam iam not inserting data from my any external file.
    For example i am inserting data from a jtabel of 1000 rows.I am getting the values from jtable and then i am inserting into database

  4. #4
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

Similar Threads

  1. Problem when insert Date to database(SQL)
    By hungleon88 in forum JDBC
    Replies: 6
    Last Post: 04-29-2009, 03:53 PM
  2. Replies: 1
    Last Post: 10-10-2008, 08:47 AM
  3. How to insert java Object in oracle database
    By Thilkumar82 in forum Advanced Java
    Replies: 9
    Last Post: 08-13-2008, 11:33 AM
  4. Probeleme with insert into database oracle
    By bachtoutou in forum New To Java
    Replies: 0
    Last Post: 05-24-2008, 11:56 AM
  5. Replies: 0
    Last Post: 02-10-2008, 11:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •