// 接收参数
String housecode;%>
<%
try
{
housecode = request.getParameter("housecode") ;
}
catch(Exception e)
{}
你这样写不太好应该:
String housecode=null;]
String sql = "DELETE FROM shackdetail,housedetail WHERE housecode=?" ;
这块一直没有值,所以删不了,你就没把获取的housecode 的值传到(WHERE housecode=?)这里面,它砸删?你那应该弄个类,然后调用就行了
String housecode;%>
<%
try
{
housecode = request.getParameter("housecode") ;
}
catch(Exception e)
{}
你这样写不太好应该:
String housecode=null;]
String sql = "DELETE FROM shackdetail,housedetail WHERE housecode=?" ;
这块一直没有值,所以删不了,你就没把获取的housecode 的值传到(WHERE housecode=?)这里面,它砸删?你那应该弄个类,然后调用就行了
mysql> create table shackdetail(id int not null, name varchar(20));
Query OK, 0 rows affected (0.01 sec)mysql>
mysql>
mysql> create table housedetail(id int not null, name varchar(20));
Query OK, 0 rows affected (0.02 sec)mysql>
mysql> insert into shackdetail values (1, 'good');
Query OK, 1 row affected (0.00 sec)mysql> insert into shackdetail values (2, 'god');
Query OK, 1 row affected (0.00 sec)mysql>
mysql> insert into housedetail values (1, 'okok');
Query OK, 1 row affected (0.00 sec)mysql> insert into housedetail values (2, 'koko');
Query OK, 1 row affected (0.00 sec)mysql>
mysql> select * from shackdetail;
+----+------+
| id | name |
+----+------+
| 1 | good |
| 2 | god |
+----+------+
2 rows in set (0.00 sec)mysql>
mysql> select * from housedetail;
+----+------+
| id | name |
+----+------+
| 1 | okok |
| 2 | koko |
+----+------+
2 rows in set (0.00 sec)mysql>
mysql>
mysql> delete from shackdetail, housedetail where id = 1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near 'where id = 1' at line 1
mysql>
mysql>这个是我模仿你的sql语句写的..你运行在后台都不保错误吗? SQLException?你的SQL语句写的有问题!
你这句不报错吗?
shackdetail 表和housedetail 表都有housecode 这样写怎么行必然会有这个错误
column ambiguously defined
另外怎么没有异常抛出呢?
一旦报错 你这几句不会执行的
rs.close();
sp.close();
conn.close();
另外jsp里面一般是不写逻辑只做展现的 建议LZ 注意这个问题
mysql支持多表删除,但是你的语句有问题。改为如下:
String sql = " delete a,b from shackdetail a, housedetail b where a.housecode = ? and b.housecode = ?";
...
ps.setString(1,***);
ps.setString(2,***);.....其他你都知道了。
mysql> create table shackdetail(id int not null, name varchar(20));
Query OK, 0 rows affected (0.02 sec)mysql> create table housedetail(id int not null, name varchar(20));
Query OK, 0 rows affected (0.00 sec)mysql> insert into shackdetail values (1, 'good');
Query OK, 1 row affected (0.00 sec)mysql> insert into shackdetail values (2, 'god');
Query OK, 1 row affected (0.00 sec)mysql> insert into housedetail values (1, 'okok');
Query OK, 1 row affected (0.00 sec)mysql> insert into housedetail values (2, 'koko');
Query OK, 1 row affected (0.02 sec)mysql> delete from shackdetail, housedetail where id = 1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that correspo
mysql> delete from shackdetail, housedetail where shackdetail.id = 1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that correspo
mysql> delete from shackdetail a, housedetail b where a.id = 1 and a.id=b.id;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that correspo
mysql> delete from shackdetail a, housedetail b where a.id = 1 and b.id = 1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that correspo
mysql> delete a,b from shackdetail a, housedetail b where a.id = 1 and b.id = 1;
Query OK, 2 rows affected (0.00 sec)mysql> select * from shackdetail;
+----+------+
| id | name |
+----+------+
| 2 | god |
+----+------+
1 row in set (0.00 sec)mysql> select * from housedetail;
+----+------+
| id | name |
+----+------+
| 2 | koko |
+----+------+
1 row in set (0.00 sec)mysql>