Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Oracle Update statement from Spark

Solved Go to solution

Oracle Update statement from Spark

New Contributor

can I execute update statement using

spark.read.format("jdbc").options(

   Map("driver" -> "oracle.jdbc.driver.OracleDriver",<br>     "url" -> url,<br>     "dbtable" -> sqlUpdate,<br>     "user" -> username,<br>     "password" -> password)).load()
?
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Oracle Update statement from Spark

@Anuj Tanwar AFAIK updates are supported with spark jdbc. Alternative is to use standard jdbc - You can read more here https://stackoverflow.com/questions/34643200/spark-dataframes-upsert-to-postgres-table

*** If you found this answer addressed your question, please take a moment to login and click the "accept" link on the answer.

View solution in original post

2 REPLIES 2
Highlighted

Re: Oracle Update statement from Spark

@Anuj Tanwar AFAIK updates are supported with spark jdbc. Alternative is to use standard jdbc - You can read more here https://stackoverflow.com/questions/34643200/spark-dataframes-upsert-to-postgres-table

*** If you found this answer addressed your question, please take a moment to login and click the "accept" link on the answer.

View solution in original post

Highlighted

Re: Oracle Update statement from Spark

New Contributor

I used OracleDataSource() to make connection and it worked.

val ods = new OracleDataSource()

ods.setUser(username)
ods.setPassword(password)
ods.setURL(url)

val connection = ods.getConnection()
connection.setAutoCommit(false)

val prepUpdateStat = connection.prepareStatement(sqlUpdate)
prepUpdateStat.execute()
connection.commit()
prepUpdateStat.close()
Don't have an account?
Coming from Hortonworks? Activate your account here