Program:
import java.sql.*;
public class BatchEx {
public static void main (String[] args) throws Exception {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = null;
String userName = "root";
String password = "root";
String url ="jdbc:mysql://localhost/abhi";
java.util.Calendar c=java.util.Calendar.getInstance();
conn = DriverManager.getConnection(url,userName,password);
PreparedStatement stmt = conn.prepareStatement("INSERT INTO xyz VALUES(?,?,?,?)");
stmt.setInt(1,15);
stmt.setInt(2,1);
c.clear();
c.set(2011,9,25);
stmt.setDate(3, new java.sql.Date((c.getTime()).getTime()));
c.set(2011,9,27);
stmt.setDate(4,new java.sql.Date((c.getTime()).getTime()));
stmt.addBatch();
stmt.setInt(1,16);
stmt.setInt(2,2);
c.clear();
c.set(2011,10,12);
stmt.setDate(3,new java.sql.Date((c.getTime()).getTime()));
c.set(2011,10,27);
stmt.setDate(4,new java.sql.Date((c.getTime()).getTime()));
stmt.addBatch();
stmt.executeBatch();
conn.close();
}
}
No comments:
Post a Comment