Fast import data to mysql in Java -


how long take insert 500.000 records csv file mysql database java code? database hosted on localhost.

table structure: ai id, | varchar(8) | datetime | int | varchar(2). code need insert 70.000 records on 40 minutes. there way faster? here main part of code:

csvreader pro  ducts = new csvreader(path); products.readheaders(); stmt = con.createstatement(); string updatestring = "insert table (t_v1, date, t_v2, t_v3) values (?,?,?,?)"; preparedstatement preparedstatement = con.preparestatement(updatestring);              while (products.readrecord()) {                 v1= products.get("v1");                 date = format.parse(products.get("date") + " " + products.get("hour"));                 java.sql.date datedb = new java.sql.date(data.gettime());                 v2 = products.get("v2");                 v3 = products.get("v3");                    preparedstatement.setstring(1, v1);                 preparedstatement.setdate(2,datedb);                 preparedstatement.setint(3, integer.parseint(v2));                 preparedstatement.setstring(4, v3);                    preparedstatement.executeupdate();             } 

according advice moved creation of statement out of loop. have 33 records per second, after had 29 rps.

i might opt using load data statement mysql instead of using java:

load data local infile '/path/to/your/file.csv' table table; 

this avoid lot of overhead have, assuming processing each line before inserting mysql.

you can execute load data statement java using raw jdbc.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -