Sunday, 29 November 2015

Time taken by MySql Driver to insert 49 values (int values into MYSQL DB)

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class First {

//@SuppressWarnings("null")
public static void main(String[] args) {

// TODO Auto-generated method stub

    try {
Connection con=null;
Statement stmt=null;
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
stmt=con.createStatement();
long t1 = System.currentTimeMillis();
for(int j=1;j<50;j++){
stmt.executeUpdate("insert into first values ("+j+")");
}
long t2 = System.currentTimeMillis();
System.out.println("Time is " +(t2-t1));
con.close();

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}

}


Output:-
Time is 21



No comments:

Post a Comment