databricks connect to SQL db

Pubblicato il: 21 marzo 2022
sul canale di: Knowledge Sharing
25,492
115

this video provides information on how to connect azure SQL db from datbaricks and transfer the data

here is the code

df = spark.read.csv('dbfs:/FileStore/tables/Legally_Operating_Businesses.csv',header="true")
display(df)

%scala
val schema = "DCALicense string,LicenseType string,LicenseExpirationDate string,LicenseStatus string,LicenseCreationDate string,Industry string,BusinessName string,BusinessName2 string,AddressBuilding string,AddressStreetName string,SecondaryAddressStreetName string,AddressCity string,AddressState string,AddressZIP string,ContactPhoneNumber string,AddressBorough string,BoroughCode string,CommunityBoard string,CouncilDistrict string,BIN string,BBL string,NTA string,CensusTract string,Detail string,Longitude string,Latitude string,Location string"

%scala

import java.util.Properties

val jdbcHostName = "dbricksconnectivity.database.windows.net"
val jdbcPort =1433
val jdbcdbName = "dbricksCon"
val myproperties = new Properties()

val jdbcUsername = dbutils.secrets.get(scope = "bricksScope", key = "sqlusername")
val jdbcPassword = dbutils.secrets.get(scope = "bricksScope", key = "sqlpassword")

myproperties.put("user",jdbcUsername)
myproperties.put("password",jdbcPassword)

val url = s"jdbc:sqlserver://${jdbcHostName}:${jdbcPort};database=${jdbcdbName}"
val driverClass = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
myproperties.setProperty("Driver", driverClass)

val mydf = spark.read.format("csv").option("header","true").schema(schema).load("dbfs:/FileStore/tables/Legally_Operating_Businesses.csv")
mydf.write.jdbc(url,"license",myproperties)

%scala
import org.apache.spark.sql.SaveMode

mydf.write.mode(SaveMode.Append).jdbc(url,"license",myproperties)


In questa pagina del sito puoi guardare il video online databricks connect to SQL db della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Knowledge Sharing 21 marzo 2022, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 25,492 volte e gli è piaciuto 115 spettatori. Buona visione!