Insert multiple rows at single statment using mySQL & Avoid date truncate error in mysql while Insert TimeStamp
Post date: Aug 9, 2011 7:20:22 AM
Before post this article i was struggled a lot to insert the multiple statement at single short in mySQL database.
I used java as front end. I separated all my insert statements by ';'.
executeBatch() is helped me to do multiple insert at single short.
String[] arrAreaStmt= areaStmts.split(";");
String[] arrImgStmt = imageStmts.split(";");
Statement stmt = connection.createStatement();
for(int i=0; i<arrAreaStmt.length; i++){
stmt.addBatch(arrAreaStmt[i]);
}
for(int i=0; i<arrImgStmt.length;i++){
stmt.addBatch(arrImgStmt[i]);
}
stmt.executeBatch();
I have an another problem in mySQL while timestamp. It show date truncate error in mysql.
By using following statement you can avoid that error.
insert into ROUTE_DETAILS(DEVICE_ID,LATITUDE,LONGITUDE,UPDATED_DT,VEHICLE_NO)
values ('352337040706319','19.1135212','73.0147768',
STR_TO_DATE('2011-08-09 12:59:49 PM', '%Y-%m-%d %h:%i:%s %p'),
'DD-45-DG-3455')