[HELP!]why get some fields is null !!
Dear All Master,
I design two jsp page for index,jsp and edit,jsp connection MS SQL 2000 + tomcat 4.0.
I am met with one problem, Index.jsp is display all profile list, it's Action field when click edit text will jump to edit.jsp and pass to your just choose that record data, but edit.jsp all fields is null just only a field have data, i dont know what to do? who can tell me, thanks you!
I will Attach to result pages!!!!
INDEX.JSP
Code:
<%@ page contentType="text/html; charset=Big5" %>
<%@ page language="java" import="java.sql.*" %>
<html>
<head>
<title>Microsoft SQL Server 2000 and JSP Sample!</title>
</head>
<body bgcolor="#ffffff">
<h1>All Person Profile</h1>
<%
Statement stmt = null;
Connection conn = null;
String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
Class.forName(driver).newInstance();
String jdbcUrl = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=DATABASE";
conn = DriverManager.getConnection(jdbcUrl, "sa", "sa");
stmt = conn.createStatement();
String query = "SELECT PersonID, PersonName, PersonBirth, PersonTel, PersonSalary FROM Person_Info";
ResultSet rs = stmt.executeQuery(query);
%>
<table border="1" width="100%">
<tr>
<td width="20%" align="center"><font size="2" face="Arial">PersonID</font></td>
<td width="20%" align="center"><font size="2" face="Arial">PersonName</font></td>
<td width="20%" align="center"><font size="2" face="Arial">PersonBirth</font></td>
<td width="20%" align="center"><font size="2" face="Arial">PersonTel</font></td>
<td width="20%" align="center"><font size="2" face="Arial">PersonSalary</font></td>
<td width="20%" align="center"><font size="2" face="Arial">Action</font></td>
</tr>
<%
while(rs.next())
{
int per_id = rs.getInt("PersonID");
String per_name = rs.getString("PersonName");
String per_birth = rs.getString("PersonBirth");
String per_tel = rs.getString("PersonTel");
double per_salary = rs.getDouble("PersonSalary");
%>
<tr>
<td width="20%" align="center"><%= per_id%></td>
<td width="20%" align="center"><%= per_name%></td>
<td width="20%" align="center"><%= per_birth%></td>
<td width="20%" align="center"><%= per_tel%></td>
<td width="20%" align="center"><%= per_salary%></td>
<td width="20%" align="center"><a href="edit.jsp?PersonTel=<%= per_tel%>">Edit</a></td>
</tr>
<%
}
%>
</table>
</body>
</html>
EDIT.JSP
Code:
<%@ page contentType="text/html; charset=Big5" %>
<%@ page language="java" import="java.sql.*" %>
<html>
<head>
<title>
edit
</title>
</head>
<body bgcolor="#ffffff">
<%
String per_id = request.getParameter("PersonID");
String per_name = request.getParameter("PersonName");
String per_birth = request.getParameter("PersonBirth");
String per_tel = request.getParameter("PersonTel");
String per_salary = request.getParameter("PersonSalary");
Connection conn = null;
Statement stmt = null;
String jdbcUrl = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=DATABASE";
conn = DriverManager.getConnection(jdbcUrl, "sa", "sa");
stmt = conn.createStatement();
String sql = "SELECT * FROM Person_Info WHERE PersonTel = '" + per_tel + "' ";
ResultSet rs = stmt.executeQuery(sql);
%>
<table border="1">
<tr>
<td align="middle" width="20%"><font face="Arial" size="2">PersonID</font></td>
<td align="middle" width="20%"><font face="Arial" size="2">PersonName</font></td>
<td align="middle" width="20%"><font face="Arial" size="2">PersonBirth</font></td>
<td align="middle" width="20%"><font face="Arial" size="2">PersonTel</font></td>
<td align="middle" width="20%"><font face="Arial" size="2">PersonSalary</font></td>
<tr>
<td align="middle" width="20%"><input type="text" name="PersonID" size="20" value="<%= per_id%>"></td>
<td align="middle" width="20%"><input type="text" name="PersonName" size="20" value="<%= per_name%>"></td>
<td align="middle" width="20%"><input type="text" name="PersonBirth" size="20" value="<%= per_birth%>"></td>
<td align="middle" width="20%"><input type="text" name="PersonTel" size="20" value="<%= per_tel%>"></td>
<td align="middle" width="20%"><input type="text" name="PersonSalary" size="20" value="<%= per_salary%>"></td>
</table>
</body>
</html>
Attached Images
Last edited by MaxiWang; 04-11-2005 at 11:21 AM .
try it
Try to add rs.next() first before presenting data to html in EDIT.JSP
you are passing only "PersonTel" to the edit.jsp page thts why its getting only that value, <a href="edit.jsp?PersonTel=<%= per_tel%>"> so if you want to pass all parameters use,
edit.jsp?PersonTel=<%= per_tel%>">&PersonID=<%=per_id%>.....
He is passing PersonTel as a search criteria to look up the record on the edit page.
What seems to be missing is that onece you read the record from the database:
String sql = "SELECT * FROM Person_Info WHERE PersonTel = '" + per_tel + "' ";
ResultSet rs = stmt.executeQuery(sql);
you don't have any code to assign those results to the variables you display. Also, if this will truly be an edit page, you will need to write the displayed and edited data back to the database when edit.jsp is closed.
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
Bookmarks