在maven中查询需要的依赖
<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.12</version></dependency>
def saveToMysql(it:Iterator[(String,Int)]):Unit = {var conn:Connection = nullvar pst:PreparedStatement = nullvar url = "jdbc:mysql://localhost:3306/company?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true"var driver = "com.mysql.cj.jdbc.Driver"//驱动和以前的有区别var name = "root"var password = "123456"try {Class.forName(driver).newInstance()conn = DriverManager.getConnection(url, name, password)pst = conn.prepareStatement("insert into mydata values(?,?)")it.foreach(x=>{pst.setString(1,x._1)pst.setInt(2,x._2)pst.executeUpdate()})} catch {case t: Throwable => t.printStackTrace()} finally {if (pst != null) pst.close()if (conn != null) conn.close()}}