cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to write dataframe to Oracle from Databricks ?

prasannar
New Contributor II
 
4 REPLIES 4

Rishabh264
Honored Contributor II
sql = "select * from tablename"
 
user = ""
 
password = ""
 
server = ""
 
port = 
 
service_name = ''
 
jdbcUrl = f"jdbc:oracle:thin:@{server}:{port}:{service_name}"
 
jdbcDriver = "oracle.jdbc.driver.OracleDriver"
 
 
 
 
 
DF = spark.read.format("jdbc") \
 
 .option("url", jdbcUrl) \
 
 .option("query", sql) \
 
 .option("user", user) \
 
 .option("password", password) \
 
 .option("driver", jdbcDriver) \
 
 .load()
 
 
 
 
 
 
 
by this you can make a connection with your oracle database and read files from the database and same you can write the data to particular database .

Rishabh Pandey

Ajay-Pandey
Esteemed Contributor III

Hi @Prasanna Lakshmi​ you can use JDBC API to write the data.

Kaniz_Fatma
Community Manager
Community Manager

Hi @Prasanna Lakshmi​, We haven’t heard from you since the last response from @Ajay Pandey​​ and @Rishabh Pandey​, and I was checking back to see if their suggestions helped you.

Or else, If you have any solution, please share it with the community, as it can be helpful to others.

Also, Please don't forget to click on the "Select As Best" button whenever the information provided helps resolve your question.

sher
Valued Contributor II
Df.write.format('jdbc').options(
      url='jdbc:oracle:thin:@192.168.11.100:1521:ORCL',
      driver='oracle.jdbc.driver.OracleDriver',
      dbtable='testschema.test',
      user='testschema',
      password='password').mode('overwrite').save()

try this. refer link: https://dwgeek.com/load-spark-dataframe-to-oracle-table-example.html/

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!