Advertisement
Guest User

Untitled

a guest
Jan 10th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. public static void main( String[] args )
  2. {
  3. String MYSQL_DRIVER = "oracle.jdbc.driver.OracleDriver";
  4. String MYSQL_CONNECTION_URL = "jdbc:oracle:thin:@//192.168.2.85:1521/stage";
  5.  
  6. JavaSparkContext sc = new JavaSparkContext(new SparkConf().setAppName("SparkJdbcDs").setMaster("local[*]"));
  7. SQLContext sqlContext = new SQLContext(sc);
  8.  
  9. Map<String, String> options = new HashMap<String, String>();
  10. options.put("driver", MYSQL_DRIVER);
  11. options.put("url", MYSQL_CONNECTION_URL);
  12. options.put("dbtable", "select * from loc_item_master");
  13. options.put("partitionColumn", "LOC_ITEM_ID");
  14. options.put("user", "ad_tables");
  15. options.put("password", "ad_tables");
  16. options.put("lowerBound", "4467");
  17. options.put("upperBound", "4749");
  18. options.put("numPartitions", "10");
  19. try {
  20. Dataset<Row> jdbcDF = sqlContext.load("jdbc", options);
  21. List<Row> employeeFullNameRows = jdbcDF.collectAsList();
  22.  
  23. for (Row employeeFullNameRow : employeeFullNameRows) {
  24. System.out.println(employeeFullNameRow);
  25. }
  26.  
  27. sc.close();
  28.  
  29. } catch (Exception e) {
  30. e.printStackTrace();
  31. }
  32.  
  33. }
  34.  
  35. <dependency>
  36. <groupId>com.databricks</groupId>
  37. <artifactId>spark-csv_2.11</artifactId>
  38. <version>1.5.0</version>
  39. </dependency>
  40. <!-- https://mvnrepository.com/artifact/com.univocity/univocity-parsers -->
  41. <dependency>
  42. <groupId>com.univocity</groupId>
  43. <artifactId>univocity-parsers</artifactId>
  44. <version>2.3.0</version>
  45. </dependency>
  46.  
  47. <dependency>
  48. <groupId>org.apache.spark</groupId>
  49. <artifactId>spark-mllib_2.11</artifactId>
  50. <version>2.0.1</version>
  51. </dependency>
  52.  
  53. <dependency> <!-- Spark dependency -->
  54. <groupId>org.apache.spark</groupId>
  55. <artifactId>spark-core_2.11</artifactId>
  56. <version>2.0.1</version>
  57. </dependency>
  58. <dependency>
  59. <groupId>org.apache.spark</groupId>
  60. <artifactId>spark-sql_2.11</artifactId>
  61. <version>2.0.1</version>
  62. </dependency>
  63.  
  64. <dependency>
  65. <groupId>com.oracle</groupId>
  66. <artifactId>ojdbc6</artifactId>
  67. <version>11.2.0.3</version>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement