开发者

deleting tables on MySQL from jdbc

开发者 https://www.devze.com 2023-04-10 07:59 出处:网络
Problem when deleting tables from jdbc I have a. jar that deletes records from multiple tables through a previously prepared statement

Problem when deleting tables from jdbc

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

开发者_JAVA百科

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.


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号