I am updating remote DB by JDBC Prepared statements.
When I execute the same code to update local DB it takes milliseconds but for remote DB it is taking too long for around 900 rows.
Size of all rows combined is 160 KB.
Remote Host is Hostgator and DB Engine for table is InnoDB.
Here is my code:
String insertTableSQL = "INSERT INTO abc(zzz,c,d,e,timestamp) VALUES (?,?,?,?,?)";
String delSt = "DELETE FROM abc WHERE zzz= ?";
del = connection.prepareStatement(delSt);
preparedStatement = connection.prepareStatement(insertTableSQL);
connection.setAutoCommit(false);
Iterator<DataObject> itr = updationList.iterator();
while (itr.hasNext()) {
DataObject dO = itr.next();
del.setString(1, dO.a + ":" + dO.b);
for (SubObject sO : dO.getsO.values()) {
try {
preparedStatement.setString(1, sO.a + ":" + sO.b);
preparedStatement.setString(2, sO.c);
preparedStatement.setInt(3, sO.d);
preparedStatement.setFloat(4, sO.e);
preparedStatement.setTimestamp(5, getCurrentTimeStamp());
preparedStatement.addBatch();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
try {
del.execute();
preparedStatement.executeBatch();
} catch (Exception e) {
e.printStackTrace();
}
try {
connection.commit();
}
...
You should check that the indexes are the same on your local table and on the remote server. The delete is likely the culprit and
EXPLAIN SELECT * FROM abc WHERE zzz=?will show you what’s going on there. You can try adding compression to your connection by addinguseCompression=trueto your JDBC connection string. This will shrink that 160k down a bit and while it’s sending commands.http://dev.mysql.com/doc/refman/5.1/en/connector-j-reference-configuration-properties.html