如何在JAVA(ResultSet)中检查Merge查询是否成功?

时间:2014-04-16 13:14:02

标签: java sql oracle

我想检查此查询是返回结果还是错误。 我使用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;
}

1 个答案:

答案 0 :(得分:1)

你可以试试这个:

........
int affected_rows_number=stmt.executeUpdate("your_query");

affected_rows_number显示受影响的行数。你可以理解它现在有效。