Options
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Rising Star
Created on 02-13-2019 09:24 PM - edited 09-16-2022 01:45 AM
I have been playing quite a bit with CDSW lately. Here is a quick article on how to setup a CDSW project in scala connecting to an external RDBMS
Step 1: Create a new CDSW Project
Using the CDSW UI, create a new Scala Project:
Step 2: Reference the external Jar in your spark-defaults.conf
Open your project, and edit your spark-defaults.conf to add an external jar:
spark.jars=http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar
Step 3: Create a simple Scala file to connect to the DB
Create a new file and add this code in it:
val sqlContext = new org.apache.spark.sql.SQLContext(sc) val df = sqlContext.read.format("jdbc").option("url", "jdbc:mysql://[YOUR_SERVER_IP]:3306/[YOUR_DB]").option("driver", "com.mysql.jdbc.Driver").option("dbtable", "[YOUR_TABLE]").option("user", "[YOUR_USER]").option("password", "[YOUR_PWD]").load() df.show()
Step 4: Run your application
Launch a session and run your code:
2,128 Views