Hi,
I open a connection,create a statement and resultset.Retrieve the info and use a while loop to retrive each row and place it in form fields so the user can edit the info. then i close the statement,connection and result set. The submit button takes them to updateprod.jsp where a new connection is opened and the info in the form fields is updated to the database and then it returns. I've pasted the code below, this code is used to retrieve the info and put it in form fields. Ive also pasted the file which should update the info.Can you have a look to see if im doing anything wrong? thanks rui
=================================================================
Update.jsp
=================================================================
<%@ page import ="java.sql.*" %>
<html>
<head>
<title>Displaying Records</title>
</head>
<body>
<%
Connection connection = null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = java.sql.DriverManager.getConnection("jdbc
dbc:rui1","admin1","rui1");
Statement statement = connection.createStatement();
ResultSet columns = statement.executeQuery("SELECT * FROM Products");
%>
<table border="0" cellspacing="0" width="100%">
<TR>
<td><font color="blue">MODEL</font></td>
<td><font color="blue">MAKE</font></td>
<td><font color="blue">DESCRIPTION</font></td>
<td></td>
<td></td>
<%
while(columns.next())
{
String model = columns.getString("Model");
%>
<TR>
<form name="update" method="post" action="UpdateProd.jsp">
<TD><input type="text" name="model" size="15" value="<%="" +model%>"></TD>
<TD><input type="text" name="make" size="15" value="<%="" +columns.getString("Product")%>"></TD>
<TD><input type="text" name="description" size="15" value="<%="" +columns.getString("Desc")%>"></TD>
<TD><input name="update" type="submit" alt="update" value="Update"></TD>
<TD><input name="delete" type="submit" alt="delete" value="Delete"></TD>
<input type="hidden" name="index" value="<%="" +model%>">
</form>
</TR>
<%
}
statement.close();
columns.close();
connection.close();
%>
<TR>
<form name="update1" method="post" action="UpdateProd.jsp">
<TD><input type="text" name="model" size="15"></TD>
<TD><input type="text" name="make" size="15"></TD>
<TD><input type="text" name="description" size="15"></TD>
<TD><input name="add" type="submit" value="Add"></TD>
<TD></TD>
</form>
</TR>
</TABLE>
</table>
</table>
<br>
</body>
</html>
=================================================================
UpdateProd.jsp
=================================================================
<%@ page import ="java.io.*"%>
<%@ page import ="java.sql.*" %>
<%@ page import ="java.util.*" %>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection = java.sql.DriverManager.getConnection("jdbc
dbc:rui","admin","rui");
%>
<%
if((request.getParameter("update")) != null)
{
String index = request.getParameter("index");
connection.setAutoCommit(false);
PreparedStatement updateProduct = connection.prepareStatement("UPDATE Products SET Product = ? WHERE Model = ?");
updateProduct.setString(1, request.getParameter("make"));
updateProduct.setString(2, index);
updateProduct.executeUpdate();
PreparedStatement updateModel = connection.prepareStatement("UPDATE Products SET Model = ? WHERE Model = ?");
updateModel.setString(1, request.getParameter("model"));
updateModel.setString(2, index);
updateModel.executeUpdate();
PreparedStatement updateDesc = connection.prepareStatement("UPDATE Products SET Desc = ? WHERE Model = ?");
updateDesc.setString(1, request.getParameter("desccription"));
updateDesc.setString(2, index);
updateDesc.executeUpdate();
connection.commit();
connection.setAutoCommit(true);
}
%>
<%
connection.close();
%>
<jsp:forword page="Update.jsp"/>
=================================================================