<p>hi i am not able to retrieve string from database to a text box in web page my code is as follows:-</p> <p><HTML> <link rel="stylesheet" type="text/css" href="format.css" > <HEAD> <TITLE>Modify Profile </TITLE> </HEAD></p> <p><%@ include file="connect.jsp"%> <% int aa,ab,ac,ad,ae,ag;</p> <p>String ia="0",ib="0",ic="0",id="0",ie="0",ig="0"; try{ String username=request.getParameter("username"); re=stmt.executeQuery("select * from userreg where username='"+username+"' "); while(re.next()) { ia=re.getString("name"); ib=re.getString("surname"); ic=re.getString("dob"); id=re.getString("email"); ie=re.getString("hintques"); ig=re.getString("hintans"); } aa=Integer.parseInt(ia); aa=aa; ab=Integer.parseInt(ib); ab=ab; ac=Integer.parseInt(ic); ac=ac; ad=Integer.parseInt(id); ad=ad; ae=Integer.parseInt(ie); ae=ae; ag=Integer.parseInt(ig); ag=ag;</p> <p>%> </p> <p><BODY></p> <div id="header"> <p align="center"> <font face="Times New Roman, Times, serif" size="15"> <b><u>PASSPORT SERVICE</u></b></font></p> <p align="center"> <font face="Times New Roman, Times, serif" size="4"> <b>REPUBLIC OF INDIA</b></font></p> </div> <div id="nav"> <center> <pre><font face="Times New Roman, Times, serif" size="3"><a href="index.html"><font color="#000066">HOME</font></a> <a href="login.html"><font color="#000066">LOGIN</font></a> <a href="process.html"><font color="#000066">PASSPORT PROCESS</font></a> <a href="cont.html"><font color="#000066">CONTACT</font></a> <a href="help.html" ><font color="#000066">HELP</font></a> <a href="adminlog.html" ><font color="#000066">ADMIN LOGIN</font></a></font></pre> </center> </div> <div id="nav1"> <p align="center"> <font face="Times New Roman, Times, serif" size="5" color="#000066"> <b><u>SERVICES</u></b></font><br><br><br> <font face="Times New Roman, Times, serif" size="4"> <a href="fpptstep1.html"><font color="#000066">FRESH/REISSUE OF PASSPORT</font></a><br><br> <a href=""><font color="#000066">VIEW APPOINTMENT AVAILABLITY</font></a><br><br> <a href="locatepsk.html"><font color="#000066">LOCATE PASSPORT OFFICE</font></a><br><br> <a href=""><font color="#000066">DOCUMENTS REQUIRED</font></a><br><br> <a href="feecalcu.html"><font color="#000066">FEE CALCULATOR</font></a><br><br> <a href=""><font color="#000066">FEEDBACK</font></a><br><br> <a href=""><font color="#000066">FAQ's</font></a> </font> </p> </div> <form action="modifypro.jsp" method="get" method="post"> <div id="content"> <br><img align="right" src="ts.jpg" height="230" width="150" > <pre> <font face="Georgia, Times New Roman, Times, serif"> <h2><b> <u>MODIFY PROFILE</u></b></h2> <table cellspacing="15"> <tr><td>Username*:</td><td><input type="text" name="username" value=""></td></tr> <tr><td>Given Name*:</td><td><input type="text" name="name" value="<%=aa%>"></td></tr> <tr><td>Surname:</td><td><input type="text" name="surname" value="<%=ab%>"></td></tr> <tr><td>Date of Birth:</td><td><input type="date" name="dob" value="<%=ac%>"></td></tr> <tr><td>Email:</td><td><input type="text" name="email" value="<%=ad%>"></td></tr> <tr><td>Hint Question:</td><td><select name="st" value="<%=ae%>" > <option>--select--</option><option>Birth Place</option><option>Fav Color</option><option>Fav Cricketer</option><option>Fav Food</option><option>First School</option><option>Fav Food</option><option>Make Of First Car Owened</option><option>Make Of First Bike Owened</option> </select></td></tr> <tr><td>Hint Answer*:</td><td><input type="text" name="hint ans" value="<%=ag%>"></td></tr> </table> <input type="Button" name="b1" value="submit" > <input type="Button" name="b1" value="Modify" onClick="val(form)" ","> <input type="reset" name="b2" value="Clear"> </p> </font> </pre> </div> </form> <div id="footer"> <center> © Copyright and Design by: Chandan and Indrajeet </center> </div> <p></BODY> <%} catch(Exception e) { <br /> out.println(e);</p> <p>}%></p> <p></HTML></p>
1)application.jsp:
<%@ page import="java.sql.*" %> <html> <head> <script language="javascript"> function editRecord(id){ var f=document.form; f.method="post"; f.action='edit.jsp?id='+id; f.submit(); } </script> </head> <body> <br><br> <form method="post" name="form"> <table border="1"> <tr><th>Name</th><th>Address</th><th>Contact No</th><th>Email</th></tr> <% Connection con = null; String url = "jdbc:mysql://localhost:3306/"; String db = "test"; String driver = "com.mysql.jdbc.Driver"; String userName ="root"; String password="root"; int sumcount=0; Statement st; try{ Class.forName(driver).newInstance(); con = DriverManager.getConnection(url+db,userName,password); String query = "select * from employee"; st = con.createStatement(); ResultSet rs = st.executeQuery(query); %> <% while(rs.next()){ %> <tr><td><%=rs.getString(2)%></td> <td><%=rs.getString(3)%></td> <td><%=rs.getString(4)%></td> <td><%=rs.getString(5)%></td> <td><input type="button" name="edit" value="Edit" style="background-color:#49743D;font-weight:bold;color:#ffffff;" onclick="editRecord(<%=rs.getString(1)%>);" ></td> </tr> <% } %> <% } catch(Exception e){ e.printStackTrace(); } %> </table> </form> </body> </html>
2)edit.jsp:
<%@page language="java"%> <%@page import="java.sql.*"%> <form method="post" action="update.jsp"> <table border="1"> <tr><th>Name</th><th>Address</th><th>Contact No</th><th>Email</th></tr> <% String id=request.getParameter("id"); int no=Integer.parseInt(id); int sumcount=0; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root"); String query = "select * from employee where id='"+no+"'"; Statement st = conn.createStatement(); ResultSet rs = st.executeQuery(query); while(rs.next()){ %> <tr> <td><input type="text" name="name" value="<%=rs.getString("name")%>"></td> <td><input type="text" name="address" value="<%=rs.getString("address")%>"></td> <td><input type="text" name="contact" value="<%=rs.getInt("contactNo")%>"></td> <td><input type="text" name="email" value="<%=rs.getString("email")%>"></td> <td><input type="hidden" name="id" value="<%=rs.getString(1)%>"></td> </tr> <tr> <td><input type="submit" name="Submit" value="Update" style="background-color:#49743D;font-weight:bold;color:#ffffff;"></td> </tr> <% } } catch(Exception e){} %> </table> </form>
continue..
3)update.jsp:
<%@page import="java.sql.*"%> <% String ide=request.getParameter("id"); int num=Integer.parseInt(ide); String name=request.getParameter("name"); String address=request.getParameter("address"); int contact=Integer.parseInt(request.getParameter("contact")); String email=request.getParameter("email"); try{ Connection conn = null; Class.forName("com.mysql.jdbc.Driver").newInstance(); conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root"); Statement st=null; st=conn.createStatement(); st.executeUpdate("update employee set name='"+name+"',address='"+address+"',contactNo="+contact+",email='"+email+"' where id='"+num+"'"); response.sendRedirect("/examples/jsp/application.jsp"); } catch(Exception e){ System.out.println(e); } %>
thank u its working............thank u very much....
Ads