Oracle-使用ant将表从一种模式复制到另一种

时间:2018-11-16 17:37:55

标签: oracle ant

我需要将一个表从一个Oracle模式复制到另一个,可以通过在schema_one中运行以下查询来完成此操作-

create table EMPLOYEES unrecoverable as select * from schema_two.EMPLOYEES;

当使用命令行或sql developer运行时有效。

但是挑战在于使用ant脚本执行此操作。

我的蚂蚁目标如下

<target name="create.tables">
        <echo message="creating tables... " />
        <sql driver="${db.driver}"  
             url="${db.url}"
             userid="${db.username}"
             password="${db.password}"
             onerror="abort"
             keepformat="yes"
             encoding="UTF-8"
            >
            <transaction>
                create table EMPLOYEES unrecoverable as select * from schema_two.EMPLOYEES;

            </transaction>
            <classpath>
                <path refid="database.common.classpath"/>
            </classpath>
        </sql>
    </target>

其中为schema_one定义了db.driver,db.url,db.username和db.password。 运行它会引发如下错误

在tnsnames.ora中也有关于架构的条目。

java.sql.SQLRecoverableException: Listener refused the connection with the following error:
ORA-12514, TNS:listener does not currently know of service requested in connect descriptor

        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:825)
        at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:751)
        at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:38)
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:593)
        at org.apache.tools.ant.taskdefs.JDBCTask.getConnection(JDBCTask.java:366)
        at org.apache.tools.ant.taskdefs.SQLExec.getConnection(SQLExec.java:963)
        at org.apache.tools.ant.taskdefs.SQLExec.execute(SQLExec.java:628)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
        at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:435)
        at org.apache.tools.ant.Target.performTasks(Target.java:456)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
        at org.apache.tools.ant.Main.runBuild(Main.java:857)
        at org.apache.tools.ant.Main.startAnt(Main.java:236)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:287)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:113)
Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error:
ORA-12514, TNS:listener does not currently know of service requested in connect descriptor

        at oracle.net.ns.NSProtocolStream.negotiateConnection(NSProtocolStream.java:324)
        at oracle.net.ns.NSProtocol.connect(NSProtocol.java:287)
        at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1963)
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:564)
        ... 22 more

0 个答案:

没有答案