我遇到了Oracle OCI jdbc驱动程序未抛出ORA-01403的问题。找不到数据异常。与Oracle 11和12有关。也许在Connection对象上需要设置属性或某些内容。瘦驱动程序正确地引发了一个异常,但是即使表中有数据,OCI驱动程序也可以继续正常运行,并且没有错误并更新0行。
以下程序的输出为:
从THIN驱动程序抛出异常:ORA-01403:找不到数据 ORA-06512:位于“ EE.TABLEX_UPSERT_PRE”的第4行 ORA-04088:执行触发器EE.TABLEX_UPSERT_PRE时出错
行从OCI驱动程序= 0更新
public static void main(String[] args) {
try {
Driver d = (Driver) Class.forName("oracle.jdbc.OracleDriver").newInstance();
Properties info = new Properties();
info.put("user", "me");
info.put("password", "mypwd");
Connection thinConnection = d.connect("jdbc:oracle:thin:@host:1521:DEV",info);
Connection ociConnection = d.connect("jdbc:oracle:oci:@DEV",info);
try {
Statement s = thinConnection.createStatement();
s.execute("UPDATE tablex SET name='newname'");
System.out.println("rows updated in THIN Driver =" + s.getUpdateCount());
}
catch (SQLException e) {
System.out.println("Exception thrown from THIN Driver: " + e.getMessage());
}
try {
Statement s = ociConnection.createStatement();
s.execute("UPDATE tablex SET name='newname'");
System.out.println("rows updated from OCI Driver =" + s.getUpdateCount());
}
catch (SQLException e) {
System.out.println("Exception thrown from OCI Driver: " + e.getMessage());
}
}
catch (Exception e) {
e.printStackTrace();
}
System.exit(0);
}
{////// SQL
CREATE TABLE TABLEX
(
NAME VARCHAR2(20)
);
INSERT INTO TABLEX(name) values('data1');
CREATE TABLE TABLEy
(
ID NUMBER
);
create or replace
TRIGGER TABLEX_UPSERT_PRE
BEFORE INSERT OR UPDATE ON TABLEX FOR EACH ROW
DECLARE
cid number;
BEGIN
select id into cid from tabley where id=0; -- INTENTIONAL No Data Found error
end;
}