
how can we increment the value of database SQL by using the java servlet program ? plz help me

Hi Friend,
Try the following code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class IncrementValue extends HttpServlet {
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("Select * from employee");
int id=0;
if(rs.last()){
id=rs.getInt("id");
}
System.out.println(id);
int ide=id+1;
int i=stmt.executeUpdate("insert into employee(id) values("+ide+")");
out.println("Id is incremeneted!");
}
catch(Exception e){
System.out.println(e);
}
}
}
Hope that it will be helpful for you.
Thanks