从jdbc中删除MySQL上的表

发布于 2024-12-07 13:27:42 字数 568 浏览 0 评论 0原文

从 jdbc 删除表时出现问题

我有一个。通过先前准备的语句从多个表中删除记录的 jar

我是这样做的:

-- SQL
delete from tabla_a using tabla_a join tabla_c join tabla_b join tabla_d
where tabla_a.tabla_c_id = tabla_c.id and tabla_c.tabla_b_id = tabla_b.id
and tabla_b.tabla_d_id = tabla_d.id and tabla_d.field = 2;

注意:where (?) is an integer

// Java
conn = DriverManager.getConnection(dsn, user, pass);
stmt = conn.createStatement();
int rows = stmt.executeUpdate(query);

不起作用不会删除任何记录,我直接将 SQL 测试到 MySQL并正常工作。

Problem when deleting tables from jdbc

I have a. jar that deletes records from multiple tables through a previously prepared statement

i did it this way:

-- SQL
delete from tabla_a using tabla_a join tabla_c join tabla_b join tabla_d
where tabla_a.tabla_c_id = tabla_c.id and tabla_c.tabla_b_id = tabla_b.id
and tabla_b.tabla_d_id = tabla_d.id and tabla_d.field = 2;

note: where (?) is an integer

// Java
conn = DriverManager.getConnection(dsn, user, pass);
stmt = conn.createStatement();
int rows = stmt.executeUpdate(query);

does not work does not erase any record, I tested the SQL directly to MySQL and working properly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

闻呓 2024-12-14 13:27:42

尝试改用PreparedStatement,并设置参数。沿着这些思路:

conn = DriverManager.getConnection(dsn, user, pass);
stmt = conn.prepareStatement(query);
stmt.setInt(1, 2);
int rows = stmt.executeUpdate();

Try using a PreparedStatement instead, and set the parameters. Something along these lines:

conn = DriverManager.getConnection(dsn, user, pass);
stmt = conn.prepareStatement(query);
stmt.setInt(1, 2);
int rows = stmt.executeUpdate();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文