使用SQLServerBulkCopy

时间:2019-07-04 20:58:28

标签: java sql-server azure etl oracle-data-integrator

我尝试使用ODI和自定义LKM将数据从SQL Server导出到Azure。 LKM中的步骤如下:

enter image description here

在“加载数据”步骤中,我使用SQLServerBulkCopy,但是当KM尝试执行 bulkCopy.setDestinationTableName(destinationTable);

它收到错误:

enter image description here

  

ODI-1228:在目标MICROSOFT_SQL_SERVER连接BJE-Azure-TEST上,任务SrcSet0(正在加载)失败。       原因:java.sql.SQLException:[FMWGEN] [SQLServer JDBC驱动程序] [SQLServer]'/'附近的语法不正确。           在weblogic.jdbc.sqlserverbase.ddb_.b(未知来源)           在weblogic.jdbc.sqlserverbase.ddb_.a(未知来源)           在weblogic.jdbc.sqlserverbase.ddb9.b(未知来源)           在weblogic.jdbc.sqlserverbase.ddb9.a(未知来源)           在weblogic.jdbc.sqlserver.tds.ddr.v(未知来源)           在weblogic.jdbc.sqlserver.tds.ddr.a(未知来源)           在weblogic.jdbc.sqlserver.tds.ddq.a(未知来源)           在weblogic.jdbc.sqlserver.tds.ddr.a(未知来源)           在weblogic.jdbc.sqlserver.ddj.m(未知来源)           在weblogic.jdbc.sqlserverbase.ddel.e(未知来源)           在weblogic.jdbc.sqlserverbase.ddel.a(未知来源)           在weblogic.jdbc.sqlserverbase.ddde.a(未知来源)           在weblogic.jdbc.sqlserverbase.ddel.v(未知来源)           在weblogic.jdbc.sqlserverbase.ddel.r(未知来源)           在weblogic.jdbc.sqlserverbase.ddde.execute(未知来源)           在oracle.odi.runtime.agent.execution.sql.SQLCommand.execute(SQLCommand.java:163)           在oracle.odi.runtime.agent.execution.sql.SQLExecutor.execute(SQLExecutor.java:102)           在oracle.odi.runtime.agent.execution.sql.SQLExecutor.execute(SQLExecutor.java:1)           在oracle.odi.runtime.agent.execution.TaskExecutionHandler.handleTask(TaskExecutionHandler.java:50)           在com.sunopsis.dwg.dbobj.SnpSessTaskSql.processTask(SnpSessTaskSql.java:2925)           在com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java:2637)           在com.sunopsis.dwg.dbobj.SnpSessStep.treatAttachedTasks(SnpSessStep.java:577)           在com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java:468)           在com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:2093)           在oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor $ 2.doAction(StartSessRequestProcessor.java:380)           在oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTemplate.java:216)           在oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.doProcessStartSessTask(StartSessRequestProcessor.java:312)           在oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.access $ 0(StartSessRequestProcessor.java:304)           在oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor $ StartSessTask.doExecute(StartSessRequestProcessor.java:874)           在oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:133)           在oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor $ 2.run(DefaultAgentTaskExecutor.java:84)           在java.lang.Thread.run(Thread.java:745)

在“加载数据”步骤中编码:

<%

        import com.microsoft.sqlserver.jdbc;
        import com.microsoft.sqlserver.jdbc.SQLServerBulkCopy;

        import java.sql.Connection;
        import java.sql.DriverManager;
        import java.sql.ResultSet;
        import java.sql.SQLException;
        import java.sql.Statement;

        //String        selectQuery             = "select TOP(10) " +odiRef.getColList("", "[EXPRESSION]", ", ", "", "")+ " from " +odiRef.getSrcTablesList("", "[SCHEMA].[TABLE_NAME] AS [POP_TAB_ALIAS]", ", ", ""); //+ " where (1=1) " +odiRef.getJoinList("and ","([EXPRESSION])"," and ","") + odiRef.getFilterList("and ","([EXPRESSION])"," and ","") + odiRef.getGrpBy() + odiRef.getHaving();
        String      selectQuery             = "select TOP(10) R03_DATA.Id, R03_DATA.ItemId, R03_DATA.StepId, R03_DATA.StepName, R03_DATA.ResultState, R03_DATA.ResultString, R03_DATA.ResultDecimal, R03_DATA.LimitLow, R03_DATA.LimitHigh, R03_DATA.ComparisonType, R03_DATA.Unit, R03_DATA.StationNo, R03_DATA.FailGroup, R03_DATA.ResultType, R03_DATA.Report, R03_DATA.Error, R03_DATA.Executiontime from dbo.r03_data AS R03_DATA ";
        String      sourceUrl                   = "***connection to MS SQL***";
        String      destinationUrl      = "***connection to Azure ***";        
        String      destinationTable    = "r03_data";
        //destinationTable  = odiRef.getTable("L", "COLL_NAME", "A");

        ResultSet SourceData;
        ResultSet DestinationData;
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

        try {
                out.println("--select query: " +selectQuery);
                Connection sourceConnection = DriverManager.getConnection(sourceUrl); 
                Statement stmt = sourceConnection.createStatement();        
                Connection destinationConnection = DriverManager.getConnection(destinationUrl);
                Statement destStmt = destinationConnection.createStatement();
                SQLServerBulkCopy bulkCopy = new SQLServerBulkCopy(destinationConnection);
                SourceData = stmt.executeQuery(selectQuery);

                DestinationData = destStmt.executeQuery(selectQuery);
                bulkCopy.setDestinationTableName(destinationTable);

                out.println("--destination table: " +destinationTable);
                out.println("--select query: " +selectQuery);
        }   catch(SQLException se)
        {
                out.println("--Exception Occured while running Flex SQL. :"+se);
        } 
%>

我猜想SQLServerBulkCopy试图将一些内容写到out.println中,然后ODI要执行它。

我也不确定我做得正确。是否存在另一种方法?

0 个答案:

没有答案