package cn.brent.sparkstreamming
import java.sql.{Connection, DriverManager}
import scala.collection.mutable.ArrayBuffer
object DBUntils {
val mysqlConf = Map(
"driver" -> "com.mysql.jdbc.Driver",
"url" -> "jdbc:mysql://192.168.239.129:3306/spark",
"username" -> "hive",
"password" -> "hive"
)
def getMysqlConn():Connection = {
Class.forName(mysqlConf("driver"))
DriverManager.getConnection(mysqlConf("url"),mysqlConf("username"),mysqlConf("password"))
}
def getBlackList():Array[String]={
val conn = getMysqlConn()
val info = new ArrayBuffer[String]()
try{
val statement = conn.createStatement()
val sql = "select website from blacklist"
val resultSet = statement.executeQuery(sql)
while(resultSet.next()){
info += resultSet.getString("website")
}
}catch {
case e : Throwable => e.printStackTrace()
}finally {
conn.close()
}
info.toArray
}
def main(args: Array[String]): Unit = {
val result = getBlackList()
println(result.toBuffer)
}
}