Spark中访问mysql连接池的封装

package com.lg.blgdata.utils

import java.util.Properties
import com.alibaba.druid.pool.DruidDataSourceFactory
import javax.sql.DataSource
import java.sql.Connection

//mysql连接池
object DruidConnectionPool{
	private val props=new Properties();
	props.put("username","root")
	props.put("password","lgg123")
	props.put("driverClassName","com.mysql.cj.jdbc.Driver")
	props.put("url","jdbc:mysql://192.168.x.xxx:3306/jzwdata?useUnicode=true&characterEncoding=utf8")

	private val source:DataSource=DruidDataSourceFactory.createDataSource(props)

	def getConnection : Connection={
		source.getConnection
	}
}

  

posted @ 2021-01-21 11:51  憨憨青年  阅读(354)  评论(0编辑  收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css