您可以使用jTDS從maven庫,添加您的集群。安裝之後,您可以編寫以下代碼來連接到數據庫。
在Scala代碼:
進口java.util。val driverClass = " net.sourceforge.jtds.jdbc屬性。司機" val serverAdd = " " val數據庫名= " " val域= " " / /使用域的活動目錄val database_port = " " val jdbcUsername = " " val jdbcPassword = " " val若幹= " jdbc: jtds::狀態"置疑" / / " + serverAdd + ": " + database_port + " /“+數據庫名+”;useNTLMv2 = true;域= " +域名+ ";" val connectionProperties =新屬性()connectionProperties.put(“用戶”,“$ {jdbcUsername} ") connectionProperties.put(“密碼”,“$ {jdbcPassword} ") connectionProperties。setProperty(“司機”,driverClass) val dataFrame = spark.read。jdbc (url =若幹表=“(select * from table_name)”,屬性= connectionProperties)