import java.io.IOException;
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AddAutoIncrementServlet extends HttpServlet
{
	public void doGet(HttpServletRequest req, HttpServletResponse res)
		throws IOException, ServletException
		{
			res.setContentType("text/html");
			PrintWriter pw = res.getWriter();
			
			String driver = "com.mysql.jdbc.Driver";
			String url = "jdbc:mysql://192.168.10.13/data";
			String uid = "root";
			String psw = "root";
			String sql = "ALTER TABLE employee CHANGE Id EmpId int auto_increment;";
			
			try{
				Class.forName(driver);
				Connection con = DriverManager.getConnection(url,uid,psw);
				PreparedStatement ps= con.prepareStatement(sql);
				int i = ps.executeUpdate();
				pw.println(i+" rows are affected");
				}
			catch(SQLException sx)
			{
				pw.println(sx);
			}
			catch(ClassNotFoundException cx)
			{
				pw.println(cx);
			}
		}
}
