当前页面: 开发资料首页 → JSP 专题 → 奇怪的问题,我删除数据后报错,但是数据已经删除了,请问错误在那里?(在线等待)
奇怪的问题,我删除数据后报错,但是数据已经删除了,请问错误在那里?(在线等待)
摘要: 奇怪的问题,我删除数据后报错,但是数据已经删除了,请问错误在那里?(在线等待)
<%@ page import="java.sql.*"%>
<%@ page contentType="text/html; charset=GBK"%>
<%
String strurl="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=D:/Java/Tomcat 4.1/webapps/ROOT/user/books.mdb";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("before connection");
Connection conn=DriverManager.getConnection(strurl);
Statement stmt=conn.createStatement();
String tablename="";
String id="";
tablename=request.getParameter("tablename");
id=request.getParameter("id");
String sql="delete "+tablename+" from id="+id;
System.out.println(sql);
ResultSet rs=stmt.executeQuery("delete from "+tablename+" where id="+id);
conn.commit();
conn.setAutoCommit(true);
conn.close();
%>
删除成功
<%
%>
=============================
以上是代码
用这个方法取出数据是没有问题的
stmt.executeUpdate
少了一个更新操作哦,明白了
还是出错,这里写错了吧,加入后数据都不能删除了
D:/Java/Tomcat 4.1/work/Standalone/localhost/_/user/del_jsp.java:58: cannot resolve symbol
symbol : method executeUpdate ()
location: interface java.sql.Statement
stmt.executeUpdate();
ResultSet rs=stmt.executeUpdate("delete from "+tablename+" where id="+id);
这样写还是出错
ResultSet rs=stmt.executeUpdate("delete from "+tablename+" where id="+id);
==>
stmt.executeUpdate("delete from "+tablename+" where id="+id);
同意楼上的,定义了rs,就说明要求有返回值,但是你删除之后没有返回值,所以错误,应该用:
stmt.executeUpdate("delete from "+tablename+" where id="+id);
就这句,不要附加什么什么=它就OK了!
哦,是不能直接定义加使用?我写到一起的缘故?
不行,还是报错,平常这个应该在我的程序上怎么写才对?不明白啊
org.apache.jasper.JasperException: No ResultSet was produced
错误提示
不需要定义ResultSet,这个只有查询的时候才用到,直接
stmt.executeUpdate("delete from "+tablename+" where id="+id);
conn.commit();
.....
就可以了
哦,那么插入和修改都是一样的操作吧??