I’ve two database connections as follows: val db1...
# exposed
n
I’ve two database connections as follows: val db1 = Database.connect( "jdbc:postgresql://localhost:5432/db1”, driver = "org.postgresql.Driver", user = "postgres", password = "password") val db2 = Database.connect( "jdbc:postgresql://localhost:5432/db2”, driver = "org.postgresql.Driver", user = "postgres", password = "password" ) Now if I run the transactions as follows, this does not work. transaction(db1){ …. } Instead, if I switch the order in which the above database connections are declared, then it will work. val db2 = Database.connect( "jdbc:postgresql://localhost:5432/db2”, driver = "org.postgresql.Driver", user = "postgres", password = "password" ) val db1 = Database.connect( "jdbc:postgresql://localhost:5432/db1”, driver = "org.postgresql.Driver", user = "postgres", password = "password") transaction(db1){ …. } Why is it so? My understanding was that every time we call the transaction with the database connection object (i.e., db1) the connection gets established. Is that not a correct understanding? Or, is that a matter of some settings/configuration? Can someone please help me? Thanks in advance
d
First off, use ``` to quote code blocks. Second, you should tell us what "doesn't work" means in your case. Are you getting an exception? Is it using the wrong db? etc..?
Also avoid having everything be italics. It makes it really hard to read with my astigmatism.
n
Thank you @Daniel Pitts for your response. I couldn't visit this channel for quite sometime, hence missed this message. Well, when I say this does not work, I meant this was not getting connected to the database. The last connection variable assigned will stay connected, as in the given example. Hope this clarifies. Thanks again!
one additional information. Both the Dbs are on the same machine and connected via same port (Postgresql).