0

I am working on Myql database and netbeans. i want to edit the table in a Jsp page and i want to place new values in it. I mean the previous data in the table must be dispalyed after that i want to edit it and replace new values ...after this changes the database must be updated with new values....

below is the code for the table data which i can only see but i cant modify it.. can some one help me out its very URGENT!!

<%@ page language="java" import="java.sql.*"%>
<html>
<head><title>Read from mySQL Database</title>
</head>
<a href="index.jsp">Home</a>
<body>

<p align="center"><b>Update from the 'registration' table.</b><br>&nbsp;</p>

<div align="center" width="85%">
<center>
<table border="1" borderColor="#ffe9bf" cellPadding="0" cellSpacing="0" width="1000" height="63">
<tbody>

<td bgColor="#008080"><font color="#ffffff"><b>First Name</b></font></td>
<td bgColor="#008080"><font color="#ffffff"><b>Last Name</b></font></td>
<td bgColor="#008080"><font color="#ffffff"><b>Gender</b></font></td>
<td bgColor="#008080"><font color="#ffffff"><b>Date Of Birth</b></font></td>
<td bgColor="#008080"><font color="#ffffff"><b>Address</b></font></td>
<td bgColor="#008080"><font color="#ffffff"><b>Country</b></font></td>
<td bgColor="#008080"><font color="#ffffff"><b>State</b></font></td>
<td bgColor="#008080"><font color="#ffffff"><b>Pin Code</b></font></td>
<td bgColor="#008080"><font color="#ffffff"><b>E-mail Id</b></font></td>
<td bgColor="#008080"><font color="#ffffff"><b>Contact</b></font></td>


<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=null;
ResultSet rst=null;
Statement stmt=null;

try{
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/Prashanth","root","");
stmt=con.createStatement();
rst=stmt.executeQuery("select * from registration ");
while(rst.next()){


%>
<tr>

<td bgColor="#ffff98" vAlign="top"><%=rst.getString("fname")%></td>
<td bgColor="#ffff98" vAlign="top"><%=rst.getString("lname")%></td>
<td bgColor="#ffff98" vAlign="top"><%=rst.getString("gender")%></td>
<td bgColor="#ffff98" vAlign="top"><%=rst.getString("dob")%></td>
<td bgColor="#ffff98" vAlign="top"><%=rst.getString("address")%></td>
<td bgColor="#ffff98" vAlign="top"><%=rst.getString("country")%></td>
<td bgColor="#ffff98" vAlign="top"><%=rst.getString("state")%></td>
<td bgColor="#ffff98" vAlign="top"><%=rst.getString("pin")%></td>
<td bgColor="#ffff98" vAlign="top"><%=rst.getString("email")%></td>
<td bgColor="#ffff98" vAlign="top"><%=rst.getString("contact")%></td>
</tr>
<% }


rst.close();
stmt.close();
con.close();
}
catch(Exception e){
System.out.println(e.getMessage());
}
%>
</tbody>
</table>
</center>
</div>


</body>

</html>

Edited by peter_budo: Correctingg closing tag from [code] to [/code]

3
Contributors
5
Replies
13
Views
6 Years
Discussion Span
Last Post by ypks_destiny
0

Re: editing the table in a database using JSP
inside the while stmt include
stmt.executeUpdate("your update querry");


NO its not working

Edited by ypks_destiny: n/a

0

If you want to update a row in your table , then come up with that table's primary key.
based on that id you can update your table and refresh that page which contain table data.
Means:
add this line after your hearder in line number 25 : <td bgColor="#008080"><font color="#ffffff"><b>Edit</b></font></td> and also insert this line after line number 52: <td bgColor="#ffff98" vAlign="top"><a href="editpage.jsp?edit_id=%=rst.getString("id")%>">Edit</a></td> then in editpage.jsp:
this page contains text boxes to enter new data, if we clicks edit link then it will go for update query some thing like : query="update registration set name=requert.getParameter("name") etc where id=requert.getParameter("id")"; After updating your query then redirect to main table data page.
then you can see edited values..

If your requirement is not this, then come up with clear information.
thanks.

Edited by Shanti C: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.