【发布时间】:2016-10-27 06:23:59
【问题描述】:
我正在尝试使用 JDBC 并使用以下命令查询数据库
CallableStatement call_state =null;
call_state =con.prepareCall("UPDATE district SET d_next_o_id = ?+1 WHERE d_id = ? AND d_w_id = ?");
call_state.setInt(1, d_next_o_id);
call_state.setInt(2, d_id);
call_state.setInt(3, d_w_id);
rs=call_state.executeQuery();`
我遇到异常:java.sql.SQLException: 无法提交空查询。
【问题讨论】:
-
尝试使用
PreparedStatement而不是CallableStatement。 -
使用
PreparedStatement和PreparedStatement.executeUpdate()。update语句不返回ResultSet -
CallableStatement用于调用过程和函数,而不是运行查询。听从之前cmets的建议,使用PreparedStatement。