日期:2014-05-20  浏览次数:20654 次

一个简单的删除操作。删除不了,那里出问题了。
主页面代码
try{ 
Connection conn = DriverManager.getConnection("jdbc:odbc:Northwind","",""); 
Statement stmt = conn.createStatement(); 
String sql="Select * FROM Test order by id DESC";
//String str="insert into Test(title,message) values('"+title+"','"+message+"')";
//stmt.execute(str); 
ResultSet rs = stmt.executeQuery(sql); 


while(rs.next()){ 


%>

<table width="747" height="32" border="1" bordercolor="#ECE9D8">
  <tr>
  <td width="55"><%=rs.getString("id" )%></td>
  <td width="156"><%=rs.getString("title" )%></td>
  <td width="342"><%=rs.getString("message")%></td>
  <td width="166"><a href="del.jsp?<%=rs.getString("id" )%>">删除 </a>   
 
<td width="166"><a href="upd.jsp">更新</a></td>
  </tr>
</table>

<%} 
rs.close(); 


删除页面代码:
try{ 
Connection conn = DriverManager.getConnection("jdbc:odbc:Northwind","",""); 
Statement stmt = conn.createStatement(); 
out.print("id");
String sql="delete from Test where id="+id;
stmt.executeUpdate(sql);

out.println("正在删除数据,请稍等。。。 。。。");
%>
  <meta http-equiv="refresh" content="2;url=hejiao.jsp" />
<% 

//stmt.execute(str); 
//ResultSet rs = stmt.executeQuery(sql); 
//rs.close(); 
stmt.close(); 
conn.close(); 

catch(Exception ex){ 
out.print(ex); 

%>


------解决方案--------------------
<td width="166"><a href="del.jsp?<%=rs.getString("id" )%>">删除 </a> 

这里,你没有把你的id传递过去啊~~

地址应该是这样:del.jsp?id=<%=rs.getString("id")%>

这样你可以从del.jsp中通过id获取过来。
------解决方案--------------------
debug debug debug!