Spark:连接oracle
代码:
val file = "/root/dir/jhzf.properties"
val tableName = "spark_timetime"
import java.util.Properties
val properties = new Properties()
import java.io.FileInputStream
properties.load(new FileInputStream(file))
properties.setProperty("dbtable", tableName)
import scala.collection.JavaConversions.propertiesAsScalaMap
// import org.apache.spark.sql.SQLContext
// val sqlContext = new SQLContext(sc)
// val df = sqlContext.read.options(properties).format("jdbc").load()
val df = spark.read.options(properties).format("jdbc").load()
执行:
spark-submit --master local[*] \
--class com.xjb.task.Test \
--jars ojdbc6.jar \
orcltest_2.11-1.0.jar \
args
## cat jhzf.properties
driver=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@10.18.2.3:1521:orcl
user=****
password=****
dbtable=table_name #或sql子语句如: (select * from table) a