一个简单的删除操作。删除不了,那里出问题了。

小杰_ 2012-02-08 11:06:56
主页面代码
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);
}
%>
...全文
125 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
molin_pp 2012-02-09
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 cai5 的回复:]
try{
Connection conn = DriverManager.getConnection("jdbc:odbc:Northwind","","");
Statement stmt = conn.createStatement();
String id = request.getParameter("id") ;
System.out.println("id===" ……
[/Quote]
刚刚引用错了,不过3楼说的也不错。
molin_pp 2012-02-09
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 newmoons 的回复:]
debug debug debug!
[/Quote]

看看你在删除页面有没有接受请求参数Id,没有的话要接收下,接收了的话,看看接收的值是不是正确,主要还是debug,调试。
lombardyangyou 2012-02-09
  • 打赏
  • 举报
回复
你没有得到ID,怎么使用呢?
五哥 2012-02-08
  • 打赏
  • 举报
回复
try{
Connection conn = DriverManager.getConnection("jdbc:odbc:Northwind","","");
Statement stmt = conn.createStatement();
String id = request.getParameter("id") ;
System.out.println("id===" + id ); //
String sql="delete from Test where id="+id;
stmt.executeUpdate(sql);

NewMoons 2012-02-08
  • 打赏
  • 举报
回复
debug debug debug!
小杰_ 2012-02-08
  • 打赏
  • 举报
回复
恩,我上 面的代码打错了,应该是
td width="166"><a href="del.jsp?id=<%=rs.getString("id" )%>">删除 </a>可是不行,
艳沐石 2012-02-08
  • 打赏
  • 举报
回复
<td width="166"><a href="del.jsp?<%=rs.getString("id" )%>">删除 </a> 

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

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

这样你可以从del.jsp中通过id获取过来。
小杰_ 2012-02-08
  • 打赏
  • 举报
回复
谢谢
呵呵
ilovefzq 2012-02-08
  • 打赏
  • 举报
回复
String sql="delete from Test where id='"+id+"'";,看看是不是varchar类型的
id

51,409

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧