https://kotlinlang.org logo
#ktor
Title
# ktor
c

cesards

01/27/2020, 4:39 AM
Hi everyone! I’m trying to build a small REST API with Ktor and I’m trying to connect to a Google Cloud PostgreSQL After almost an entire day trying different things, I didn’t get it working At first, I thought the problem might be related to not using the right url and driver when connecting the Database with the Expose library (I tried different urls and none of them worked). Since Google has samples relying on Hikari to get a connection pool working, I also tried it with no luck. I think the problem might be related to the fact that I’m deploying the Ktor backend using app engine (via app engine gradle plugin), which relies on:
Copy code
<servlet-class>io.ktor.server.servlet.ServletApplicationEngine</servlet-class>
and I think the Driver used by Cloud PostgreSQL might be different than the one needed? I’m not sure if what I’m saying makes sense but I’m getting crazy trying to make this work. Has anyone deployed Ktor on Google Cloud that also connects to an external database? Is it recommended? I guess the other alternative is using h2 and have a local database, but then looking at data I guess it becomes more complicated, doesn’t it? I’m quite new to the backend world, so any suggestions are more than appreciated.
c

cy

01/27/2020, 9:53 AM
What exact errors do you see?
c

cesards

01/27/2020, 12:11 PM
Copy code
Caused by:
java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=jdbc:postgresql:///xxx
	at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:114)
	at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:321)
	at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:110)
	at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:108)
	at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81)
and
Copy code
java.sql.SQLException: No suitable driver
	at java.sql/java.sql.DriverManager.getDriver(DriverManager.java:299)
	at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:106)
	at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:321)
	at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:110)
	at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:108)
	at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:81)
I’m using Hikari to do the connection, but that’s because I coudln’t make it work with Exposed 😕
j

jfburdet

01/29/2020, 12:55 PM
are you sure that the postgresql driver is included as a dependency in your build.gradle ?
26 Views