SCALIKEJDBC Study notes (1)

Source: Internet
Author: User
Tags stack trace

BUILD.SBT:

Import Sbt._import process._import Keys._eclipsekeys.createsrc: = Eclipsecreatesrc.default + Eclipsecreatesrc.resourcelazy val commonsettings = Seq (Name: = "Scalalearning", Version: = "1.0", scalaversion: = "2.10.6" ) Lazy val root = (Project in file (".")).  Settings (commonsettings: _*).  Settings (librarydependencies ++= Seq (  "ORG.SCALIKEJDBC" percent "SCALIKEJDBC"       % "3.0.0",  "MySQL"% " Mysql-connector-java "%" 5.1.40 ",  " Ch.qos.logback "  %  " logback-classic "   %" 1.2.3 ",  " Org.scalariform "percent" scalariform "%" 0.1.8 "  )  )
import Scalikejdbc._ object Simpledemo {def main (args:array[string]): Unit = { Class.forName ("Com.mysql.jdbc.Driver") Val url = "Jdbc:mysql://192.168.1.151:3306/scalalearning?useunicode=true      &characterencoding=utf8 "Val userName =" root "val password =" 12345 "val settings = connectionpoolsettings ( InitialSize = 5, maxSize = 1, Connectiontimeoutmillis = 3000L, Validationquery = "Select from Dual" ) Connectionpool.singleton (URL, userName, password, settings) Case class User (Id:int, name:string, Age:int) VA L Allcolumns = (rs:wrappedresultset) = = User (id = rs.int ("id"), name = rs.string ("name"), age = Rs.int    ("Age")) Val Users:list[user] = DB readOnly {implicit session = = SQL ("SELECT * from User limit"). Map (allcolumns). List. Apply ()} for (user <-users) {println (user.id + "," + User.Name + "," + User.age)}}} 

Operation Result:

  [SQL execution]   SELECT * from user limit 10; (2 ms)  [Stack Trace]    ...    com.citi.scalikejdbc.simpledemo$ $anonfun $2.apply (simpledemo.scala:29)    com.citi.scalikejdbc.simpledemo$$ Anonfun$2.apply (simpledemo.scala:28)    Scalikejdbc. Dbconnection$class.readonly (dbconnection.scala:202)    Scalikejdbc. Db.readonly (db.scala:60)    Scalikejdbc. db$ $anonfun $readonly$1.apply (db.scala:175)    Scalikejdbc. db$ $anonfun $readonly$1.apply (db.scala:174)    Scalikejdbc. Loanpattern$class.using (loanpattern.scala:18)    Scalikejdbc. Db$.using (db.scala:140)    Scalikejdbc. Db$.readonly (db.scala:174)    com.citi.scalikejdbc.simpledemo$.main (simpledemo.scala:28)    Com.citi.scalikejdbc.SimpleDemo.main (Simpledemo.scala) ...    1,sky,202,bill,30

SCALIKEJDBC Study notes (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.