Skip to content

Instantly share code, notes, and snippets.

@j-thepac
Last active April 11, 2024 11:47
Show Gist options
  • Save j-thepac/5da1bdd420c047d3fc73aa8a0f0d6a1a to your computer and use it in GitHub Desktop.
Save j-thepac/5da1bdd420c047d3fc73aa8a0f0d6a1a to your computer and use it in GitHub Desktop.
drop Table using Synapse Notebook
/*.
supports to 4 parameter types: int, float, bool, string.
%run /<path>/Notebook1 { "parameterInt": 1, "parameterFloat": 2.5, "parameterBool": true, "parameterString": "abc" }.
*/
%%spark
import com.microsoft.azure.synapse.tokenlibrary.TokenLibrary
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
val server = "myserver.sql.azuresynapse.net"
val dbname = "db_name"
val authKey = mssparkutils.credentials.getToken("DW")
val ds = new SQLServerDataSource()
ds.setServerName(server)
ds.setDatabaseName(dbname)
ds.setAccessToken(authKey)
var connection: Connection = null
try {
connection = ds.getConnection
val stmt = connection.createStatement
stmt.executeUpdate("DROP TABLE cca_pricing.T")
} catch {
case e: Throwable => println(e.getMessage)
} finally {
if (connection != null && !connection.isClosed) {
connection.close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment