Java SQL 1 million rows

Varuzhan Stepanyan

I must add 1.000.000 rows in mySQL with Java, but the process is quite long․ I have this code:

for(int number=45000000;number<46000000;number++){

query="insert into free(number) values ("+"'"+number+"');";
try {
    stmt.executeUpdate(query);
    System.out.println(number +" added");
} catch (SQLException e) {
    e.printStackTrace();
}

How to accelerate the process? (40 min = 100.000 rows) Any ideas?

Elliott Frisch

You could use a PreparedStatement and batching. Something like,

String query = "insert into free(number) values (?)";
PreparedStatement ps = null;
try {
    ps = conn.prepareStatement(query);
    for (int number = 45000000; number < 46000000; number++) {
        ps.setInt(1, number);
        ps.addBatch();
        if ((number + 1) % 100 == 0) { // <-- this will add 100 rows at a time.
            ps.executeBatch();
        }
    }
    ps.executeBatch();
} catch (SQLException e) {
    e.printStackTrace();
} finally {
    if (ps != null) {
        try {
            ps.close();
        } catch (SQLException e) {
        }
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

python postgres can I fetchall() 1 million rows?

From Dev

What would be the fastest way to insert 2.5 million rows of data parsed from a text file, into Sql server

From Dev

Django pagination. What if I have 1 million of rows?

From Dev

How to get a data range in a million rows dataset

From Dev

Fastest way to insert 1 million rows in SQL Server

From Dev

SQL Server - insert/select slow after TRUNCATE TABLE has 6 over million rows

From Dev

SQL Server BULK INSERT of Over 1 Million rows - Need Performance Improvement

From Dev

Sorting of 1 million integers ranging from 1 to 9 using Java code

From Dev

Slow Query on Medium MySQL Table (1 Million Rows)

From Dev

Excel : Need to delete about 1 million blank rows

From Dev

Excel VBA Performance - 1 million rows - Delete rows containing a value, in less than 1 min

From Dev

Loading 5 million rows into Pandas from MySQL

From Dev

Heroku destroy_all 1/2 million rows seems to hang

From Dev

Changing Collation did not effect on million rows of a table in SQL Server 2012 Database

From Dev

Java 1 million index array of 1x3 arrays - memory and efficiency

From Dev

Mysql group by won't use index after 1 million rows

From Dev

Java SQL 1 million rows

From Dev

How can I keep 1 million digit in Java?

From Dev

SQL - Delete table with 372 million rows starting from first row

From Dev

memory allocation in collection of 1 million references in java

From Dev

How to compare huge table(100 million rows) data between Oracle and SQL Server

From Dev

count the unique values in one column in EXCEL 2010 or R with 1 million rows

From Dev

Slow Query on Medium MySQL Table (1 Million Rows)

From Dev

Query optimization on a Table with 1 Million rows

From Dev

Doctrine native query(createNativeQuery) select query for 1 million rows high memory usage

From Dev

memory allocation in collection of 1 million references in java

From Dev

Optimizing SQL query on table of 10 million rows: neverending query

From Dev

I need to transfer 1 million rows over the internet using Web API and JSON

From Dev

Sql-Data purging on the basis of datetime column in the table having 10+ million rows

Related Related

  1. 1

    python postgres can I fetchall() 1 million rows?

  2. 2

    What would be the fastest way to insert 2.5 million rows of data parsed from a text file, into Sql server

  3. 3

    Django pagination. What if I have 1 million of rows?

  4. 4

    How to get a data range in a million rows dataset

  5. 5

    Fastest way to insert 1 million rows in SQL Server

  6. 6

    SQL Server - insert/select slow after TRUNCATE TABLE has 6 over million rows

  7. 7

    SQL Server BULK INSERT of Over 1 Million rows - Need Performance Improvement

  8. 8

    Sorting of 1 million integers ranging from 1 to 9 using Java code

  9. 9

    Slow Query on Medium MySQL Table (1 Million Rows)

  10. 10

    Excel : Need to delete about 1 million blank rows

  11. 11

    Excel VBA Performance - 1 million rows - Delete rows containing a value, in less than 1 min

  12. 12

    Loading 5 million rows into Pandas from MySQL

  13. 13

    Heroku destroy_all 1/2 million rows seems to hang

  14. 14

    Changing Collation did not effect on million rows of a table in SQL Server 2012 Database

  15. 15

    Java 1 million index array of 1x3 arrays - memory and efficiency

  16. 16

    Mysql group by won't use index after 1 million rows

  17. 17

    Java SQL 1 million rows

  18. 18

    How can I keep 1 million digit in Java?

  19. 19

    SQL - Delete table with 372 million rows starting from first row

  20. 20

    memory allocation in collection of 1 million references in java

  21. 21

    How to compare huge table(100 million rows) data between Oracle and SQL Server

  22. 22

    count the unique values in one column in EXCEL 2010 or R with 1 million rows

  23. 23

    Slow Query on Medium MySQL Table (1 Million Rows)

  24. 24

    Query optimization on a Table with 1 Million rows

  25. 25

    Doctrine native query(createNativeQuery) select query for 1 million rows high memory usage

  26. 26

    memory allocation in collection of 1 million references in java

  27. 27

    Optimizing SQL query on table of 10 million rows: neverending query

  28. 28

    I need to transfer 1 million rows over the internet using Web API and JSON

  29. 29

    Sql-Data purging on the basis of datetime column in the table having 10+ million rows

HotTag

Archive