Spark Shell删除mysql主要测试用

spark-shell --jars hdfs:///cmcc/loan/jars/mysql-connector-java-5.1.38.jar

var cn: java.sql.Connection = null
var ps: java.sql.PreparedStatement = null
val sql = "delete from model_bin_result where month='201803' and model_id='1234567890' "
val driver = "com.mysql.jdbc.Driver" 
val url="jdbc:mysql://49.4.65.196:3306/mysql?useUnicode=true&characterEncoding=utf8&useSSL=false"
Class.forName(driver)
try {
cn = java.sql.DriverManager.getConnection(url, "root", "root")
ps = cn.prepareStatement(sql)
ps.execute()
} catch {
case e: Exception => println("Mysql Exception")
} finally {
if (ps != null) {
ps.close()
}
if (cn != null) {
cn.close()
}
}

你可能感兴趣的:(Spark Shell删除mysql主要测试用)