创建configuration时,发现URLParser找不到,于是只能使用配置文件来,当然使用配置文件比使用URL初始化还要直观些
def configurationWithPassword = newConfiguration(
host= "localhost",
port= 3306,
username= "root",
password= Some("123"),
database= Some("test")
)
Configuration文件本身是case class,它的code是
case classConfiguration(username: String,
host: String= "localhost",
port: Int= 5432,
password: Option[String]=None,
database: Option[String]=None,
charset: Charset=Configuration.DefaultCharset,
maximumMessageSize: Int= 16777216,
allocator: AbstractByteBufAllocator=PooledByteBufAllocator.DEFAULT,
connectTimeout: Duration= 5.seconds,
testTimeout: Duration= 5.seconds
)
这让我想到了slick,slick我连配置文件都搞不出来。总觉得slick的设计有些反人类。
对于单连接
def sinConnection: MySQLConnection ={
val configuration: Configuration=configurationWithPasswordnewMySQLConnection(configuration)
}
对于线程池连接
def poolConnection: ConnectionPool[MySQLConnection] ={
val configuration: Configuration=configurationPool
val factory= newMySQLConnectionFactory(configuration)
val pool= newConnectionPool[MySQLConnection](factory, PoolConfiguration.Default)
pool
}
ResultSet并不是java.sql.resultSet而是作者自己创建的新类型
trait ResultSet extends IndexSeq[RowData]
而rowData则表示一行数据,也是一个顺序表
trait RowData extends IndexedSeq[Any]
这样,ResultSet就像是个二维表了
原文:http://www.cnblogs.com/xinsheng/p/4336066.html