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

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -