Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main( String[] args )
- {
- String MYSQL_DRIVER = "oracle.jdbc.driver.OracleDriver";
- String MYSQL_CONNECTION_URL = "jdbc:oracle:thin:@//192.168.2.85:1521/stage";
- JavaSparkContext sc = new JavaSparkContext(new SparkConf().setAppName("SparkJdbcDs").setMaster("local[*]"));
- SQLContext sqlContext = new SQLContext(sc);
- Map<String, String> options = new HashMap<String, String>();
- options.put("driver", MYSQL_DRIVER);
- options.put("url", MYSQL_CONNECTION_URL);
- options.put("dbtable", "select * from loc_item_master");
- options.put("partitionColumn", "LOC_ITEM_ID");
- options.put("user", "ad_tables");
- options.put("password", "ad_tables");
- options.put("lowerBound", "4467");
- options.put("upperBound", "4749");
- options.put("numPartitions", "10");
- try {
- Dataset<Row> jdbcDF = sqlContext.load("jdbc", options);
- List<Row> employeeFullNameRows = jdbcDF.collectAsList();
- for (Row employeeFullNameRow : employeeFullNameRows) {
- System.out.println(employeeFullNameRow);
- }
- sc.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- <dependency>
- <groupId>com.databricks</groupId>
- <artifactId>spark-csv_2.11</artifactId>
- <version>1.5.0</version>
- </dependency>
- <!-- https://mvnrepository.com/artifact/com.univocity/univocity-parsers -->
- <dependency>
- <groupId>com.univocity</groupId>
- <artifactId>univocity-parsers</artifactId>
- <version>2.3.0</version>
- </dependency>
- <dependency>
- <groupId>org.apache.spark</groupId>
- <artifactId>spark-mllib_2.11</artifactId>
- <version>2.0.1</version>
- </dependency>
- <dependency> <!-- Spark dependency -->
- <groupId>org.apache.spark</groupId>
- <artifactId>spark-core_2.11</artifactId>
- <version>2.0.1</version>
- </dependency>
- <dependency>
- <groupId>org.apache.spark</groupId>
- <artifactId>spark-sql_2.11</artifactId>
- <version>2.0.1</version>
- </dependency>
- <dependency>
- <groupId>com.oracle</groupId>
- <artifactId>ojdbc6</artifactId>
- <version>11.2.0.3</version>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement