Hi, This line configures the database connections:
DB.defineConnectionManager(DefaultConnectionIdentifier, DBVendor) This is using only the DefaultConnectionIdentifier, which you don't want to use. You want to change this to use your 2 defined identifiers. Ie: DB.defineConnectionManager(OneDB, DBVendor) DB.defineConnectionManager(TwoDB, DBVendor) Tim On Sun, Dec 6, 2009 at 4:17 AM, Neil.Lv <anim...@gmail.com> wrote: > > Here is the db url, > > db.url1=jdbc:mysql://localhost:3306/blog1 > db.url2=jdbc:mysql://localhost:3306/blog2 > > Cheers, > Neil > > On Dec 6, 4:00 pm, "Neil.Lv" <anim...@gmail.com> wrote: >> In the Boot.scala >> ### >> class Boot { >> def boot { >> if (!DB.jndiJdbcConnAvailable_?) >> DB.defineConnectionManager(DefaultConnectionIdentifier, >> DBVendor) >> ... >> } >> >> } >> >> object WahDB extends ConnectionIdentifier { >> def jndiName = "one"} >> >> object WahereDB extends ConnectionIdentifier { >> def jndiName = "two" >> >> } >> >> object DBVendor extends ConnectionManager { >> ... >> private def createOne(name: ConnectionIdentifier): Box[Connection] = >> try { >> val dbUrl1: String = Props.get("db.url1") openOr >> "jdbc:derby:lift_example;create=true" >> >> val dbUrl2: String = Props.get("db.url2") openOr >> "jdbc:derby:lift_example;create=true" >> >> var dbUrl: String = dbUrl1 >> >> try{ >> name match { >> case One => { >> dbUrl = dbUrl1 >> } >> case Two => { >> dbUrl = dbUrl2 >> } >> case lift => { >> dbUrl = dbUrl1 >> } >> } >> } catch { >> case e : Exception => e.printStackTrace; Empty >> } >> ... >> } >> ... >> >> } >> >> In the every models: >> class User extends MegaProtoUser[User] { >> def getSingleton = User // what's the "meta" server >> >> ... >> >> override def dbCalculateConnectionIdentifier = { // >> ################## dbCalculateConnectionIdentifier >> case _ => One >> } >> >> } >> >> class Blog extends LongKeyedMapper[Item] with IdPK { >> def getSingleton = Blog // what's the "meta" server >> >> ... >> >> override def dbCalculateConnectionIdentifier = { // >> ################## dbCalculateConnectionIdentifier >> case _ => Two >> }} >> >> ### >> >> I add the "override def dbCalculateConnectionIdentifier" method in >> every models >> >> But everytime it uses the database One, never uses the database Two. >> >> Thanks very much! >> >> Cheers, >> Neil >> >> On Dec 6, 3:02 pm, "Neil.Lv" <anim...@gmail.com> wrote: >> >> > The two databases that have different structure of the tables, such >> > as two applications databases. >> >> > Cheers, >> > Neil >> >> > On Dec 6, 2:38 pm, "Neil.Lv" <anim...@gmail.com> wrote: >> >> > > Btw, there is the error message when the server is started. >> > > ### >> > > scala.MatchError: ConnectionIdentifier(lift) >> > > ### >> >> > > On Dec 6, 1:47 pm, "Neil.Lv" <anim...@gmail.com> wrote: >> >> > > > Hi all, >> >> > > > I want to use two databases, but i don't know how to configure it. >> >> > > > Does anybody know that how to configure two database connection in >> > > > Lift? >> >> > > > 1: >> > > > I add two ConnectionIdentifier in the Boot.class >> > > > ### >> > > > object OneDB extends ConnectionIdentifier { >> >> > > > def jndiName = "one" >> >> > > > } >> >> > > > object TwoDB extends ConnectionIdentifier { >> >> > > > def jndiName = "two" >> >> > > > } >> >> > > > ### >> >> > > > 2: In the User model >> >> > > > How can i write the code in the method, >> > > > ### >> > > > override def dbCalculateConnectionIdentifier = { >> > > > Two >> > > > } >> > > > ### >> >> > > > Thanks for any suggestion! >> >> > > > Cheers, >> > > > Neil > > -- > > You received this message because you are subscribed to the Google Groups > "Lift" group. > To post to this group, send email to lift...@googlegroups.com. > To unsubscribe from this group, send email to > liftweb+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/liftweb?hl=en. > > > -- You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.