赞
踩
gradle中添加依赖
implementation 'org.springframework.boot:spring-boot-starter-jdbc:2.1.5.RELEASE'
implementation 'mysql:mysql-connector-java:6.0.2'
== 特别注意引入的mysql-connector 版本,
!!!如果是6以上的版本则需要添加 “com.mysql.cj.jdbc.Driver”;否则添加“com.mysql.jdbc.Driver” ==
@JvmField var DIRECT_BASE_URL = "jdbc:mysql://**.**.**.**:3306/testDBName?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false&serverTimezone=GMT%2B8"
@JvmField var DIRECT_BASE_USERNAME = "db_account"
@JvmField var DIRECT_BASE_PASSWORD = "db_password"
@JvmField var DIRECT_BASE_DRIVER_NAME="com.mysql.cj.jdbc.Driver"
//mysql connetor 版本低于6是使用低版本,6以上的则使用上述版本
//@JvmField var DIRECT_BASE_DRIVER_NAME_LOW="com.mysql.jdbc.Driver"
@JvmStatic private var connection: Connection? = null @JvmStatic private fun dataConnectionPostgres(): Connection { val url = BootProperties.DIRECT_BASE_URL val username = BootProperties.DIRECT_BASE_USERNAME val password = BootProperties.DIRECT_BASE_PASSWORD Class.forName(BootProperties.DIRECT_BASE_DRIVER_NAME) var conn: Connection? = DriverManager.getConnection(url, username, password) return conn!! } @JvmStatic fun connection() : Connection { if (connection == null) { connection = dataConnectionPostgres() } return connection!! }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。