向MySQL数据库中插入内容:(方法传入参数为一个元组RDD)
def insertResult(record: Iterator[(String, String, String, String, String, String, String, String, String, String, Int, Int)]): Unit = {
var conn: Connection = null
var stmt: PreparedStatement = null
try {
val url = "jdbc:mysql://localhost:3306/streaminglog"
val user = "root"
val password = ""
conn = getConnection(url, user, password)
record.foreach(p => {
// 建表: create table streaming(d varchar(50), h varchar(50), hh varchar(50), fm varchar(50), m varchar(50), brand varchar(50), mallid varchar(50), cityid varchar(50), activityid varchar(50), channelid varchar(50), countnum Integer(20), money Integer(20));
val sql = "insert into streaming(d, h, hh, fm, m, brand, mallid, cityid, activityid, channelid, countnum, money) values(?,?,?,?,?,?,?,?,?,?,?,?)