Click here to Skip to main content
15,881,872 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
try {
// String id = request.getParameter("id");
String uname = request.getParameter("uname");
String pwd = request.getParameter("upwd");
String email = request.getParameter("uemailId");
String country = request.getParameter("ucountry");

Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url, "root", "root");
// PreparedStatement pst =(PreparedStatement) conn.prepareStatement("insert into untitled (id,fname,lastname) values ('2','naval','hedau')");

String sql = "insert into user_reg_ml (id,uname,pwd,email,country) values (?,?,?,?,?)";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setString(1, "13");
pst.setString(2, uname);
pst.setString(3, pwd);
pst.setString(4, email);
pst.setString(5, country);

int i = pst.executeUpdate();
String msg = "";
if (i != 0) {
//msg = "Record has been inserted";
//pw.print("" + msg + "");
HttpSession sess = request.getSession();
sess.setAttribute("uname", request.getParameter("uname"));
sess.setAttribute("pwd", request.getParameter("cpwd"));
RequestDispatcher dispatcher = request.getRequestDispatcher("/mypage1.jsp");
dispatcher.forward(request, response);
File dir = new File("D:\\nameoffolder\\" + uname);
dir.mkdir();

} else {
msg = "failed to insert the data";
pw.print("" + msg + "");
}
pst.close();

} catch (Exception e) {
pw.println(e);
}
processRequest(request, response);


here i want the id values to get incremented automatically, I have altered the table and made the value to autoincrement, also passed null values but it ain't working.
Posted
Comments
Richard MacCutchan 13-Oct-15 5:25am    
"but it ain't working." is not a very useful explanation of your problem.
Luis Carlos Gonzalez Barcenas 26-Oct-15 16:00pm    
Try passing the value as null
String sql = "insert into user_reg_ml (id,uname,pwd,email,country) values (null ,?,?,?,?)";
Also if you will insert every value for one row in that table, only do
String sql = "insert into user_reg_ml values (null ,?,?,?,?)";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900