import
java.sql.Connection;
import
java.sql.DriverManager;
import
java.sql.PreparedStatement;
import
java.sql.SQLException;
import
java.sql.Statement;
public
class
insertion {
public
static
void
main(String[] args)
throws
Exception
{
try
{
Class.forName(
"com.mysql.jdbc.Driver"
);
Connection con = DriverManager.getConnection(
Statement st = con.createStatement();
String sql
=
"insert into emp (eid,ename) values (?, ?)"
;
PreparedStatement pstmt;
pstmt = con.prepareStatement(sql);
final
int
batchSize =
5000
;
int
count =
0
;
for
(
int
i =
4000
; i <=
4500
; i++) {
pstmt.setString(
1
,
"181FA0"
+ i);
pstmt.setString(
2
,
"181FA0"
+ i);
pstmt.addBatch();
count++;
if
(count % batchSize ==
0
) {
System.out.println(
"Commit the batch"
);
pstmt.executeBatch();
}
pstmt.executeBatch();
}
}
catch
(Exception e) {
System.out.println(
"Error:"
+ e.getMessage());
}
}
}