marty001 发表于 2018-10-3 10:41:07

在lift中使用mysql

import _root_.net.liftweb.common._  import _root_.net.liftweb.util._
  import _root_.net.liftweb.http._
  import _root_.net.liftweb.sitemap._
  import java.sql.{DriverManager, Connection}
  import com.desu.model.Message
  import net.liftweb.mapper._
  class Boot {
  def boot {
  if (!DB.jndiJdbcConnAvailable_?) {
  DB.defineConnectionManager(DefaultConnectionIdentifier, DBVendor)
  }
  // where to search snippet
  LiftRules.addToPackages("com.desu")
  Schemifier.schemify(true,    Schemifier.infoF _, Message)
  // Build SiteMap
  val entries = Menu(Loc("Home", List("index"), "Home")) ::
  Menu(Loc("update", List("update"), "The Update Page")) ::
  Nil
  LiftRules.setSiteMap(SiteMap(entries:_*))
  }
  }
  object DBVendor extends ConnectionManager {
  def newConnection(name: ConnectionIdentifier): Box = {
  try {

  >  val conn = DriverManager.getConnection("jdbc:mysql://localhost/wstock?user=root&password=")
  Full(conn)
  } catch {
  case e : Exception => e.printStackTrace; Empty
  }
  }

  def>  }

页: [1]
查看完整版本: 在lift中使用mysql