示例#1
0
  private static void executeExt(Connection gpConn, int connectionId, String selectSQL)
      throws Exception {
    String method = "executeExt";
    int location = 1000;

    String sourceType = "";
    String sourceServer = "";
    String sourceInstance = "";
    int sourcePort = 0;
    String sourceDatabase = "";
    String sourceUser = "";
    String sourcePass = "";
    String strSQL = "";
    Connection conn = null;
    int fetchSize = 10;

    try {
      location = 3000;

      ResultSet rs;
      Statement stmt;

      location = 3010;
      strSQL = GP.getExtConnectionDetails(gpConn, connectionId);

      location = 3020;
      stmt = gpConn.createStatement();

      location = 3030;
      rs = stmt.executeQuery(strSQL);

      while (rs.next()) {
        sourceType = rs.getString(1);
        sourceServer = rs.getString(2);
        sourceInstance = rs.getString(3);
        sourcePort = rs.getInt(4);
        sourceDatabase = rs.getString(5);
        sourceUser = rs.getString(6);
        sourcePass = rs.getString(7);
      }

      location = 3090;
      if (sourceType.equals("sqlserver")) {
        location = 3100;
        conn = CommonDB.connectSQLServer(sourceServer, sourceInstance, sourceUser, sourcePass);

        location = 3300;
        // execute the SQL Statement
        CommonDB.outputData(conn, selectSQL);

        location = 3400;
        conn.close();

      } else if (sourceType.equals("oracle")) {
        location = 4000;
        fetchSize = Integer.parseInt(GP.getVariable(gpConn, "oFetchSize"));

        location = 4100;
        conn =
            CommonDB.connectOracle(
                sourceServer, sourceDatabase, sourcePort, sourceUser, sourcePass, fetchSize);

        location = 4200;
        // execute the SQL Statement
        CommonDB.outputData(conn, selectSQL);

        location = 4400;
        conn.close();
      }

    } catch (SQLException ex) {
      throw new SQLException(
          "(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
    } finally {
      if (conn != null) conn.close();
    }
  }