内容简介:ScalikeJDBC是一个Scala的JDBC框架,官网说easy-to-use and very flexible,易用又灵活~3、排错1)版本
ScalikeJDBC是一个Scala的JDBC框架,官网说easy-to-use and very flexible,易用又灵活~
1、添加依赖
<dependency>
<groupId>org.scalikejdbc</groupId>
<artifactId>scalikejdbc_2.11</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.197</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
</dependency>
2、上代码
import scalikejdbc._
object MySQLDAO {
def main(args: Array[String]): Unit = {
// initialize JDBC driver & connection pool
Class.forName("org.h2.Driver")
ConnectionPool.singleton("jdbc:mysql:///film?characterEncoding=utf8", "root", "root")
val id = 1
val name = "复联%"
val value = sql"""select * from movie where name LIKE $name ORDER BY id DESC """
println(value)
// simple example
val lasts: List[Map[String, Any]] = DB.readOnly { implicit session =>
sql"""select * from movie where name LIKE $name ORDER BY id DESC """.map(_.toMap()).list.apply()
}
println(lasts)
}
}
3、排错
1)版本
java.lang.NoSuchMethodError: scala.Product.$init$
这种方法找不到的问题通常都是jar包没引对或版本不一致, pom.xml 中配置的 scalikejdbc_2.11 必须和系统sdk的scala版本一致(也是2.11.x)
2)MySQL时区
java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
这是因为 mysql-connector-java 的版本是 8.0.15
解决方法:要么换成 5.1.x 的版本,或者在cmd mysql客户端输入 set global time_zone = '+8:00';
同样可以解决在IDEA的DataSource配置中连不上 MySQL 的时候。(08001错误)
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- tcp 长连接与短连接
- 没有 HTTP 连接池,空谈什么持久连接
- Linux中软连接和硬连接的区别
- sql – 哪个更好..左外连接还是右外连接?
- 连接池中的连接失效的几种处理方案
- 解决golang使用elastic连接elasticsearch时自动转换连接地址
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Types and Programming Languages
Benjamin C. Pierce / The MIT Press / 2002-2-1 / USD 95.00
A type system is a syntactic method for automatically checking the absence of certain erroneous behaviors by classifying program phrases according to the kinds of values they compute. The study of typ......一起来看看 《Types and Programming Languages》 这本书的介绍吧!