我想检查此查询是返回结果还是错误。
我使用next()
方法,对于 SELECT 查询同步,它检查是否有下一行但不确定 MERGE
public ResultSet example{
String sqlQuery = "MERGE INTO bonuses b "
+"USING ( "
+"SELECT employee_id, salary, dept_no "
+"FROM employee@link_to) e "
+"ON (b.employee_id = e.employee_id) "
+"WHEN MATCHED THEN "
+"UPDATE SET b.bonus = e.salary * 0.1 "
+"WHEN NOT MATCHED THEN "
+"INSERT (b.employee_id, b.bonus) "
+"VALUES (e.employee_id, e.salary * 0.05) "
PreparedStatement stmt = conn.prepareStatement(sql);
ResultSet rs;
try {
rs = stmt.executeQuery();
Err.errN(rs);
} finally {
}
return rs;
}
答案 0 :(得分:1)
你可以试试这个:
........
int affected_rows_number=stmt.executeUpdate("your_query");
affected_rows_number
显示受影响的行数。你可以理解它现在有效。