Click to See Complete Forum and Search --> : Updating data on JSP


florida
01-27-2005, 05:39 PM
I want to make an update page that lists records where I can click on the record link and edit the record. I have the Record viewing page set up and working where it shows the links but now when I click on the record link to get an update page it shows the correct argument ID in updater.jsp page URL but it doesnt show the record. Here is what I have:

Record viewing page:

<%@ page import="java.sql.*" %>
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); %>

<% Connection connection = DriverManager.getConnection("jdbc:odbc:theDSN", "", "");
Statement statement = connection.createStatement();
ResultSet resultset = null;

resultset = statement.executeQuery("select * from tableOne");
%>

<%
while(resultset.next())
{
%>
<a href="updater.jsp?NameID=<%= resultset.getString("NameID") %>">
edit</A><br>

<%
}
%>


updater.jsp

<%@ page import="java.sql.*" %>
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); %>

<% Connection connection = DriverManager.getConnection("jdbc:odbc:theDSN", "", "");
Statement statement = connection.createStatement();
String myID = request.getParameter("NameID");
ResultSet resultset = statement.executeQuery("select * from tableOne where NameID like '" + myID + "'");
%>

<% while(resultset.next())
{
%>
<%= resultset.getString("NameID") %><br>

<% } %>
<%
resultset.close();
connection.close();
%>



The NameID value does not show up on the action page.

ray326
01-27-2005, 10:02 PM
Assume a lotus position and chant 1000 "Model View Controllers".

View(jsp)->Get Record(servlet)->Update(jsp)
Update(jsp)->Update Record(servlet)->View(jsp)

All database access happens in the servlets. Results are passed in beans in the request.

Rethink your design in those terms and it becomes trivial.

florida
01-28-2005, 05:44 AM
My books dont cover this. Is there a tutorial site that I can look at to help me with this??

Or can you post an example to get me started?

ray326
01-28-2005, 10:34 PM
This one's oft refered to as an intro. A lot of what you find on the web relates specifically to an MVC implementation called Struts but nobody needs that extra complication as they're trying to absorb the concepts of the MVC pattern.

http://www.javaworld.com/javaworld/jw-12-1999/jw-12-ssj-jspmvc.html