How did you put the main method and what errors do you get?
You need to learn how to create and test Java programs before starting to write JSPs.
You need to learn how to create and test Java programs before starting to write JSPs.
package com.proname; import java.sql.Connection; import java.sql.DriverManager; //import java.sql.ResultSet; import java.sql.Statement; import java.sql.PreparedStatement; public class editproclass { String vFirstName; String vLastName; String vMobileNumber; String vAddress; String vCountryId; String vCityName; String vPinCode; String theEmail; Statement stmt = null; PreparedStatement ps = null; public String getvFirstName() { return vFirstName; } public void setvFirstName(String vFirstName) { this.vFirstName = vFirstName; } public String getvLastName() { return vLastName; } public void setvLastName(String vLastName) { this.vLastName = vLastName; } public String getvMobileNumber() { return vMobileNumber; } public void setvMobileNumber(String vMobileNumber) { this.vMobileNumber = vMobileNumber; } public String getvAddress() { return vAddress; } public void setvAddress(String vAddress) { this.vAddress = vAddress; } public String getvCountryId() { return vCountryId; } public void setvCountryId(String vCountryId) { this.vCountryId = vCountryId; } public String getvCityName() { return vCityName; } public void setvCityName(String vCityName) { this.vCityName = vCityName; } public String getvPinCode() { return vPinCode; } public void setvPinCode(String vPinCode) { this.vPinCode = vPinCode; } public String getTheEmail() { return theEmail; } public void setTheEmail(String theEmail) { this.theEmail = theEmail; } public Statement getStmt() { return stmt; } public void setStmt(Statement stmt) { this.stmt = stmt; } public PreparedStatement getPs() { return ps; } public void setPs(PreparedStatement ps) { this.ps = ps; } public class editproclass(){ } public main(String[] args) { try { Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/registration","root","root"); //String query ="update regist set First_Name='"+vFirstName+"'", Last_Name='"+vLastName+"'", Mobile_Number='"+vMobileNumber+"'", Address='"+vAddress+"'", City_Name='"+vCityName+"'", Country_Id='"+vCountryId+"'", Pin_Code='"+vPinCode+"'" where Email_Id='"+theEmail+"'"; PreparedStatement ps ; String vFirstName ; String vLastName ; String vMobileNumber ; String vAddress ; String vCountryId ; String vCityName ; String vPinCode ; String theEmail ; ps = con.prepareStatement("update regist set First_Name=?, Last_Name=?, Mobile_Number=?, Address=?, City_Name=?, Country_Id=?, Pin_Code=? where Email_Id='"+theEmail+"'"); ps.setString(1, vFirstName); ps.setString(2, vLastName); ps.setString(3,vMobileNumber); ps.setString(4,vAddress); ps.setString(5,vCityName); ps.setString(6,vCountryId); ps.setString(7,vPinCode); ps.executeUpdate(); con.close(); } catch(Exception e) { e.printStackTrace(); } } } //like that.
//editproAction.jsp <%@page import="java.sql.*"%> <%@page import="com.proname.editproclass" %> <% // PreparedStatement ps = null; //ResultSet rs = null; //Statement st = null; String vFirstName=request.getParameter("firstName"); String vLastName=request.getParameter("lastName"); String vMobileNumber=request.getParameter("mobileNumber"); String vAddress=request.getParameter("address"); String vCountryId=request.getParameter("countryId"); String vCityName=request.getParameter("cityName"); String vPinCode=request.getParameter("pinCode"); String theEmail = session.getAttribute("theEmail").toString(); editproclass e=new editproclass(); e.setvFirstName(vFirstName); e.setvLastName(vLastName); e.setvMobileNumber(vMobileNumber); e.setvAddress(vAddress); e.setvCountryId(vCountryId); e.setvCityName(vCityName); e.setvPinCode(vPinCode); // System.out.print("hello"); %> <jsp:forward page="record-success.jsp"></jsp:forward> //editproclass.java package com.proname; import java.sql.Connection; import java.sql.DriverManager; //import java.sql.ResultSet; import java.sql.Statement; import java.sql.PreparedStatement; public class editproclass { String vFirstName; String vLastName; String vMobileNumber; String vAddress; String vCountryId; String vCityName; String vPinCode; String theEmail; Statement stmt = null; PreparedStatement ps = null; public String getvFirstName() { return vFirstName; } public void setvFirstName(String vFirstName) { this.vFirstName = vFirstName; } public String getvLastName() { return vLastName; } public void setvLastName(String vLastName) { this.vLastName = vLastName; } public String getvMobileNumber() { return vMobileNumber; } public void setvMobileNumber(String vMobileNumber) { this.vMobileNumber = vMobileNumber; } public String getvAddress() { return vAddress; } public void setvAddress(String vAddress) { this.vAddress = vAddress; } public String getvCountryId() { return vCountryId; } public void setvCountryId(String vCountryId) { this.vCountryId = vCountryId; } public String getvCityName() { return vCityName; } public void setvCityName(String vCityName) { this.vCityName = vCityName; } public String getvPinCode() { return vPinCode; } public void setvPinCode(String vPinCode) { this.vPinCode = vPinCode; } public String getTheEmail() { return theEmail; } public void setTheEmail(String theEmail) { this.theEmail = theEmail; } public Statement getStmt() { return stmt; } public void setStmt(Statement stmt) { this.stmt = stmt; } public PreparedStatement getPs() { return ps; } public void setPs(PreparedStatement ps) { this.ps = ps; } //public class editproclass(){ //} public void main(String[] args) { try { Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/registration","root","root"); //String query ="update regist set First_Name='"+vFirstName+"'", Last_Name='"+vLastName+"'", Mobile_Number='"+vMobileNumber+"'", Address='"+vAddress+"'", City_Name='"+vCityName+"'", Country_Id='"+vCountryId+"'", Pin_Code='"+vPinCode+"'" where Email_Id='"+theEmail+"'"; PreparedStatement ps ; String vFirstName = null ; String vLastName = null ; String vMobileNumber = null ; String vAddress = null ; String vCountryId = null ; String vCityName = null ; String vPinCode = null ; String theEmail = null ; ps = con.prepareStatement("update regist set First_Name=?, Last_Name=?, Mobile_Number=?, Address=?, City_Name=?, Country_Id=?, Pin_Code=? where Email_Id='"+theEmail+"'"); ps.setString(1, vFirstName); ps.setString(2, vLastName); ps.setString(3,vMobileNumber); ps.setString(4,vAddress); ps.setString(5,vCityName); ps.setString(6,vCountryId); ps.setString(7,vPinCode); ps.executeUpdate(); con.close(); } catch(Exception e) { e.printStackTrace(); } } }
<!-- code for testing --> <% String First_Name1="",Last_Name1="", Mobile_Number1="", Address1="", City_Name1="", Country_Id1="", Pin_Code1=""; try{ Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/registration","root","root"); Statement st=con.createStatement(); String sql="select First_Name, Last_Name, Mobile_Number, Address, City_Name, Country_Id, Pin_Code from regist where Email_Id='"+session.getAttribute( "theEmail" )+"'"; ResultSet rs=st.executeQuery(sql); System.out.println(sql); while(rs.next()) { First_Name1 = rs.getString("First_Name"); Last_Name1 = rs.getString("Last_Name"); Mobile_Number1 = rs.getString("Mobile_Number"); Address1 = rs.getString("Address"); City_Name1 = rs.getString("City_Name"); Country_Id1 = rs.getString("Country_Id"); Pin_Code1 = rs.getString("Pin_Code"); } } catch(Exception e) { out.println(e); } %> <!-- end of code testing --> <table width="99%" align="center"> <tbody><tr> <td width="80%" valign="top"> <!--table width="99%" bgColor="#FF0000" cellspacing="1" cellpadding="5"><tr><td align="center" bgColor="#FCB1A7"><b><br>Warning - we noticed that you are not participating in Special Promotions. Please register on the advertiser pages with genuine data, else the frequency of Special Promotions will be reducted in your account.<br><br></b></td></tr></table--> <table cellpadding="0" cellspacing="0" border="0" width="500" align="center" style="font-family:verdana;font-size:12px" background="images/11.jpg"> <tbody><tr> <td width="4"> </td> <td width="71"><font color="#66FFFF" size="2">Edit Profile</font></td> <td width="8"> </td> <td background="images/table_bg.gif" width="406"> </td> <td width="10" background="images/table_bg.gif"><img src="pixel(1).gif" width="10" height="1" border="0"></td> </tr> <tr> <td background="line_l.gif"><img src="images/pixel(1).gif" border="0"></td> <td colspan="3"> <img src="pixel(1).gif" width="1" height="10" border="0"><br> <table cellpadding="0" cellspacing="0" border="0" width="102%"> <tbody><tr><td bgcolor="#DBEAF5"> <!-- This is the profile edit form --> <form action="editproAction.jsp" method="post"> <table cellspacing="1" cellpadding="2" border="0" width="100%" style="font-family:verdana;font-size:12px"> <tbody><tr bgcolor="#99FFFF"> <td id="t_email"> Email:<span class="inputHighlighted">*</span></td> <td><b><input type="text" name="emailId" size="30" value="<%= session.getAttribute( "theEmail" ) %>" disabled="disabled"></input></b></td> </tr><tr bgcolor="#99FFFF"> <td id="t_uname" width="30%"> First Name:<span class="inputHighlighted">*</span></td> <td><input type="text" name="firstName" id="firstName" size="35" class="ctrl" value=<%=First_Name1%>></td> </tr> <tr bgcolor="#99FFFF"> <td id="t_uname" width="30%"> Last Name:<span class="inputHighlighted">*</span></td> <td><input type="text" name="lastName" id="lastName" size="35" class="ctrl" value="<%=Last_Name1%>"></td> </tr> <tr bgcolor="#99FFFF"> <td id="t_password"> Mobile Number: <span class="inputHighlighted">*</span></td> <td><input type="text" name="mobileNumber" id="mobileNumber" size="35" class="ctrl" value="<%=Mobile_Number1%>"></td> </tr> <tr bgcolor="#99FFFF"> <td id="t_password"> Address: <span class="inputHighlighted">*</span></td> <td><textarea name="address" id="address" rows="4" cols="35" ><%=Address1%></textarea><small><br><br><b>Note:</b> We will send your payment cheques to this address.</small></td> </tr> <tr bgcolor="#99FFFF"> <td id="t_password_copy" nowrap=""> Country :<span class="inputHighlighted">*</span> </td> <td><input type="text" name="countryId" id="countryId" size="35" class="ctrl" value="<%=Country_Id1%>"> <%-- // <option value=<%=Country_Id1%>><%=Country_Id1%></option> // <option>"+rs.getString("Country_Id")+"</option> --%> </td> </tr> <tr bgcolor="#99FFFF"> <td id="t_password_copy" nowrap=""> City :<span class="inputHighlighted">*</span> </td> <td><input type="text" name="cityName" id="cityName" size="35" class="ctrl" value="<%=City_Name1%>"> </td> </tr> <tr bgcolor="#99FFFF"> <td id="t_password"> PIN Code (Zip): <span class="inputHighlighted">*</span></td> <td><input type="text" name="pinCode" id="pinCode" size="35" class="ctrl" value="<%=Pin_Code1%>"></td>
<%@page import="java.sql.*"%> <%@page import="com.proname.editproclass" %> <% // PreparedStatement ps = null; //ResultSet rs = null; //Statement st = null; String vFirstName=request.getParameter("firstName"); String vLastName=request.getParameter("lastName"); String vMobileNumber=request.getParameter("mobileNumber"); String vAddress=request.getParameter("address"); String vCountryId=request.getParameter("countryId"); String vCityName=request.getParameter("cityName"); String vPinCode=request.getParameter("pinCode"); String theEmail = session.getAttribute("theEmail").toString(); editproclass e=new editproclass(); e.setvFirstName(vFirstName); e.setvLastName(vLastName); e.setvMobileNumber(vMobileNumber); e.setvAddress(vAddress); e.setvCountryId(vCountryId); e.setvCityName(vCityName); e.setvPinCode(vPinCode); e.setTheEmail(theEmail); String V=e.implement(); if(V.equals("success")) { %> <jsp:forward page="record-success.jsp"></jsp:forward> <% } else { %> <jsp:forward page="edit_profile.jsp"></jsp:forward> <% } %>
package com.proname; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; public class editproclass { String vFirstName; String vLastName; String vMobileNumber; String vAddress; String vCountryId; String vCityName; String vPinCode; String theEmail; String var=""; PreparedStatement ps = null; public String getvFirstName() { return vFirstName; } public void setvFirstName(String vFirstName) { this.vFirstName = vFirstName; } public String getvLastName() { return vLastName; } public void setvLastName(String vLastName) { this.vLastName = vLastName; } public String getvMobileNumber() { return vMobileNumber; } public void setvMobileNumber(String vMobileNumber) { this.vMobileNumber = vMobileNumber; } public String getvAddress() { return vAddress; } public void setvAddress(String vAddress) { this.vAddress = vAddress; } public String getvCountryId() { return vCountryId; } public void setvCountryId(String vCountryId) { this.vCountryId = vCountryId; } public String getvCityName() { return vCityName; } public void setvCityName(String vCityName) { this.vCityName = vCityName; } public String getvPinCode() { return vPinCode; } public void setvPinCode(String vPinCode) { this.vPinCode = vPinCode; } public String getTheEmail() { return theEmail; } public void setTheEmail(String theEmail) { this.theEmail = theEmail; } public String getVar() { return var; } public void setVar(String var) { this.var = var; } public PreparedStatement getPs() { return ps; } public void setPs(PreparedStatement ps) { this.ps = ps; } public String implement(){ try { Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/registration","root","root"); Statement st = con.createStatement(); ResultSet res = st.executeQuery("select * from regist where Email_Id='"+theEmail+"'"); if(res.next()==true) { ps = con.prepareStatement("update regist set First_Name=?, Last_Name=?, Mobile_Number=?, Address=?, City_Name=?, Country_Id=?, Pin_Code=? where Email_Id='"+theEmail+"'"); ps.setString(1, vFirstName); ps.setString(2, vLastName); ps.setString(3, vMobileNumber); ps.setString(4, vAddress); ps.setString(5, vCountryId); ps.setString(6, vCityName); ps.setString(7, vPinCode); ps.executeUpdate(); con.close(); var="success"; } else { var="fail"; } } catch(Exception e) { System.out.println(e); } return var; } }
Comment