首页 > 解决方案 > Java 插入到其他 Schema 中的表中

问题描述

在 SQL Developer 中使用 INSERT 和 SELECT 到其他模式时,由于 Synonym,我可以毫无问题地进行 INSERT 和 SELECT,但是如果我尝试在 java 代码中执行相同操作,它会说:

ORA-00942: 表或视图不存在

连接是通过

Class.forName("oracle.jdbc.driver.OracleDriver");

从 app.properties 文件加载的属性

InputStream in = this.getClass().getClassLoader().getResourceAsStream("app.properties");

标签: javasqlpropertiesschemasql-insert

解决方案


它将通过带有 includeSynonyms = true 的属性连接来工作

java.util.Properties info = new java.util.Properties();
info.put("user", user);
info.put("password", pwd);
info.put ("includeSynonyms", "true");

然后通过使用属性进行连接

conn = DriverManager.getConnection(url, info);

这样它就可以工作了


推荐阅读