做毕业设计遇到的数据库删除问题
请高手请教,我查了好多书上的例子,运行后都有同样的错误.
错误是:只会显示第一条数据记录,后面就发生了SQL异常.
我知道错误就在那个"删除"操作的地址连接上,但是不知道怎么改,也不知道错误究竟是什么.我在下面我贴的例子里标出来,麻烦哪位大侠给我看一下.
谢谢
<%@page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.* " errorPage= " "%>
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<link href= "css/style.css " type= "text/css " rel= "stylesheet ">
<%
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
Connection connection;
Statement s;
ResultSet rs;
connection=DriverManager.getConnection( "jdbc:odbc:testDB ", "sa ", "513278 ");
s=connection.createStatement();
boolean flag = false;
if (request.getParameter( "id ") != null) {
String id = request.getParameter( "id ");
String sql = "delete from tb_userOperation where id= ' " + id + " ' ";
if (s.executeUpdate(sql)!=0) {
flag = true;
}
}
%>
<title> 删除指定记录 </title>
</head>
<body>
<table width= "500 " height= "395 " border= "0 " cellpadding= "0 " cellspacing= "0 " align= "center ">
<tr>
<td background= "images/1.gif " align= "center "> <table border= "0 " >
<tr align= "center ">
<td width= "80 "> 编号 </td>
<td width= "80 "> 姓名 </td>
<td width= "80 "> 性别 </td>
<td width= "80 "> 职业 </td>
<td width= "80 "> 操作 </td>
</tr>
<%
String selectSql = "select * from tb_userOperation ";
rs = s.executeQuery(selectSql);
try {
while (rs.next()) {
%>
<tr align= "center ">
<td> <%=rs.getString( "id ")%> </td>
<td> <%=rs.getString( "name ")%> </td>
<td> <%=rs.getString( "sex ")%> </td>
<td> <%=rs.getString( "profession ")%> </td>
<td> <a href= "index.jsp?id= <%=rs.getString( "id ")%> "> 删除 </a> </td> </tr>
<%}} catch (Exception e) {} %>
</table>
<%
if (flag) {
out.print( "删除数据成功!!! ");
}
%> </td>
</tr>
</table>
</body>
</html>
[解决办法]
问题解决了,我来接分了.
[解决办法]
lz把数据库tb_userOperation表的建表和插入测试数据的代码贴出来。
好帮你调试。
[解决办法]
不知道你这个连接是否能正确显示啊?