mysql asyn 實戰

來源:互聯網
上載者:User

標籤:

建立configuration時,發現URLParser找不到,於是只能使用設定檔來,當然使用設定檔比使用URL初始化還要直觀些

  def configurationWithPassword = new Configuration(    host = "localhost",    port = 3306,    username = "root",    password = Some("123"),    database = Some("test")  )

 

Configuration檔案本身是case class,它的code是

case class Configuration(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 = configurationWithPassword    new MySQLConnection(configuration)  }

 

對於線程池串連

  def poolConnection: ConnectionPool[MySQLConnection] = {    val configuration: Configuration = configurationPool    val factory = new MySQLConnectionFactory(configuration)    val pool    = new ConnectionPool[MySQLConnection](factory, PoolConfiguration.Default)    pool  }

 

ResultSet並不是java.sql.resultSet而是作者自己建立的新類型

trait ResultSet extends IndexSeq[RowData]

而rowData則表示一行資料,也是一個順序表

trait RowData extends IndexedSeq[Any]

這樣,ResultSet就像是個二維表了

 

mysql asyn 實戰

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.