2016-08-03 100 views
0

我正在嘗試在Teradata上使用ScalikeJdbc,但似乎無法使其工作。我有一個配置文件:Scalikejdbc teradata「連接池尚未初始化。」

application.conf 

# JDBC settings 
db.default.user="user" 
db.default.password="pass" 
# Connection Pool settings 
db.default.poolInitialSize=10 
db.default.poolMaxSize=20 
db.default.connectionTimeoutMillis=1000 

# Teradata 
db.default.driver="com.teradata.jdbc.TeraDriver" 
db.default.url="jdbc:teradata://url/database=db" 

的代碼看起來是這樣的:

import scalikejdbc._ 
import scalikejdbc.config._ 


object DBObject { 
    DBs.setupAll() 

    case class Ad(id: Long, siteId: Int) 
    object Ad extends SQLSyntaxSupport[Ad] { 
    override val tableName = "ad_table" 

    def apply(rs: WrappedResultSet) = new Ad(rs.long("id"), rs.int("ad")) 
    } 

    ConnectionPool.borrow("default") 
    val ad = Ad.syntax("ad") 
    val ads = DB(ConnectionPool.borrow()) readOnly { implicit session => 
    withSQL { 
     select.from(Ad as ad).where.eq(ad.siteId, 3001).limit(10) 
    }.map(rs => Ad(rs)).list.apply 
    } 
} 

當運行這個例子,它拋出一個異常:Connection pool is not yet initialized. 缺少什麼我在這裏?

回答

0

蒂姆,我想這並不取決於具體的Teradata。只要嘗試初始化默認連接池。 Postgres的小例子:

object Main extends App { 

    def run() = { 
    Class.forName("org.postgresql.Driver") 
    val poolSettings = new ConnectionPoolSettings(initialSize = 100, maxSize = 100) 
    val url = "jdbc:postgresql://localhost:5432/test" 
    val user = "postgres" 
    val password = "postgres" 

    // create singleton(default) connection pool 
    ConnectionPool.singleton(url, user, password, poolSettings) 

    DB.localTx { implicit session ⇒ 
     val foos = Foo.findAll() 
     println(foos) 
    } 
    } 

    run() 
} 
相關問題