Guest User

Untitled

a guest
Jan 26th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.71 KB | None | 0 0
  1.   def connectToDatabase () {
  2.       Class.forName("com.mysql.jdbc.Driver");
  3.       val username = "xx"
  4.       val password = "xxx"
  5.  
  6.       var session = Session.create(
  7.               java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/xxx", username, password),
  8.               new MySQLAdapter)
  9.  
  10.       SessionFactory.concreteFactory = Some(()=> session)
  11.                      
  12.       session.bindToCurrentThread
  13.   }
  14.  
  15.   def disconnectFromDatabase () {
  16.       var session = Session.currentSession
  17.       session.close
  18.   }
  19.  
  20.  
  21. (then in the Servlet)
  22.  
  23.  
  24.     before() {
  25.         emailrecorder.connectToDatabase()
  26.     }
  27.    
  28.     after() {
  29.         emailrecorder.disconnectFromDatabase()
  30.     }
Add Comment
Please, Sign In to add comment