Dan Storm
10/23/2023, 12:58 PMfun Application.connectToPostgres(embedded: Boolean): Connection {
Class.forName("org.postgresql.Driver")
if (embedded) {
return DriverManager.getConnection("jdbc:<postgresql://localhost:5432/db?user=user&password=password>")
} else {
val url = environment.config.property("postgres.url").getString()
val user = environment.config.property("postgres.user").getString()
val password = environment.config.property("postgres.password").getString()
return DriverManager.getConnection(url, user, password)
}
}
I then tried to do the following:
val dbConnection: Connection = connectToPostgres(embedded = true)
Database.connect({ dbConnection })
transaction {
SchemaUtils.create(com.example.app.models.Systems)
}
This results in the following error.
Exception in thread "main" org.postgresql.util.PSQLException: This connection has been closed.
But if I instead just run the following:
Database.connect("jdbc:<postgresql://localhost:5432/db?user=user&password=password>", driver = "org.postgresql.Driver")
transaction {
SchemaUtils.create(com.example.app.models.Systems)
}
Things work as expected.
Might you be able to tell me what the difference is?