Insert Record in Remote Base using Batch in mysql from JAVA

1

I'm inserting records into a remote mysql database and I do it using a java desktop batch. What I find strange is that, although I manage to insert, the time it takes me seems too much, approximately 2 minutes (500 records). The consultation is particularly, what is the optimal way to do this operation, the truth I did not find anything different from what I am doing. Thank you very much

 Connection dbConnection = ncw.getDBConnection();//conexion a la base en servidor del hosting
        dbConnection.setAutoCommit(false);
        PreparedStatement pst = dbConnection.prepareStatement("INSERT INTO tabla (campo1, campo2, campo3, campo4, campo5, campo6,campo7,campo8, campo9, campo10,campo11,campo12) VALUES (?,?,?,?,?,?,?,?,?,?,?)"); 

        int filas = nc.getCantFilas();
        for (int i = 0; i < filas; i++) {
            for (int f = 0; f < 12; f++) {          
                pst.setString(f, nc.getDato(i, f)); 
                             }
            pst.addBatch();
        }
         pst.executeBatch();
        dbConnection.commit();
    
asked by Nairda17 23.08.2018 в 02:13
source

0 answers