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

Java SQL 1 million rows

From Dev

Fastest way to insert 1 million rows in SQL Server

From Dev

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

From Dev

Query optimization on a Table with 1 Million rows

From Dev

memory allocation in collection of 1 million references in java

From Dev

memory allocation in collection of 1 million references in java

From Dev

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

From Dev

python postgres can I fetchall() 1 million rows?

From Dev

Excel : Need to delete about 1 million blank rows

From Dev

Heroku destroy_all 1/2 million rows seems to hang

From Dev

Slow Query on Medium MySQL Table (1 Million Rows)

From Dev

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

From Dev

Slow Query on Medium MySQL Table (1 Million Rows)

From Dev

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

From Dev

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

From Dev

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

From Dev

How can I keep 1 million digit in Java?

From Dev

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

From Dev

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

From Dev

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

From Dev

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

From Dev

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

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

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

From Dev

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

From Dev

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

From Dev

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

From Dev

How to get a data range in a million rows dataset

From Dev

Loading 5 million rows into Pandas from MySQL

Related Related

  1. 1

    Java SQL 1 million rows

  2. 2

    Fastest way to insert 1 million rows in SQL Server

  3. 3

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

  4. 4

    Query optimization on a Table with 1 Million rows

  5. 5

    memory allocation in collection of 1 million references in java

  6. 6

    memory allocation in collection of 1 million references in java

  7. 7

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

  8. 8

    python postgres can I fetchall() 1 million rows?

  9. 9

    Excel : Need to delete about 1 million blank rows

  10. 10

    Heroku destroy_all 1/2 million rows seems to hang

  11. 11

    Slow Query on Medium MySQL Table (1 Million Rows)

  12. 12

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

  13. 13

    Slow Query on Medium MySQL Table (1 Million Rows)

  14. 14

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

  15. 15

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

  16. 16

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

  17. 17

    How can I keep 1 million digit in Java?

  18. 18

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

  19. 19

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

  20. 20

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

  21. 21

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

  22. 22

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

  23. 23

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

  24. 24

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

  25. 25

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

  26. 26

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

  27. 27

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

  28. 28

    How to get a data range in a million rows dataset

  29. 29

    Loading 5 million rows into Pandas from MySQL

HotTag

Archive