Oracle JDBC:如何知道哪一行引发唯一键约束?

编程入门 行业动态 更新时间:2024-10-10 02:16:07
本文介绍了Oracle JDBC:如何知道哪一行引发唯一键约束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个Oracle查询,正在尝试使用jdbc执行.以下是查询.

I have an oracle query which i am trying to execute using jdbc. Following is the query.

insert into bd_vehicles_temp select * from bd_vehicles_temp_1

表bd_vehicles_temp_1包含大约7000-10000行.如果bd_vehicles_temp_1中已经存在bd_vehicles_temp_1中的主键,则会得到一个SQLException:唯一键约束.

table bd_vehicles_temp_1 contains about 7000-10000 rows. If a primary key in bd_vehicles_temp_1 is already present in bd_vehicles_temp i get an SQLException : Unique key constraint.

在我的代码中,例外行是偏离路线pstmt.executeUpdate().有没有一种方法可以精确定位bd_vehicles_temp_1中导致异常的行.

the line of exception is offcourse pstmt.executeUpdate() in my code. Is there a way to pinpoint the row in bd_vehicles_temp_1 which causes exception.

还是我必须遍历bd_vehicles_temp_1中的行并逐行插入每一行?

Or do i have to do loop through rows in bd_vehicles_temp_1 and insert each row one by one ?

预先感谢!

推荐答案

如果您知道会导致异常的列,则可以使用(特定于Oracle)

If you know the column that can cause the exception you can use (Oracle specific)

SELECT col FROM bd_vehicles_temp INTERSECT SELECT col FROM bd_vehicles_temp_1;

标识两个表中的所有行.

to identify all rows that are in both tables.

更多推荐

Oracle JDBC:如何知道哪一行引发唯一键约束?

本文发布于:2023-10-19 02:01:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1506061.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:一键   Oracle   JDBC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!