Sunday, 29 November 2015

MySql PreparedStatment to insert rows


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

public class First {

public static void main(String[] args) {
// TODO Auto-generated method stub
Connection con=null;

try {
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
PreparedStatement stmt = con.prepareStatement("insert into first values (?)");
long t1 = System.currentTimeMillis();
for(int i=1;i<=10;i++){
stmt.setInt(1, i);
stmt.executeUpdate();
}
long t2 = System.currentTimeMillis();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}


Output:-

No comments:

Post a Comment