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
 
3 REPLIES 3

Rishabh-Pandey
Esteemed Contributor
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.

Ajay Kumar Pandey

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/

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group