crewpvp / skcrew

Skript addon contains favorite addons and something more
https://skcrew.crewpvp.xyz/en
GNU General Public License v3.0
15 stars 1 forks source link

PostgreSQL Database: No suitable driver #22

Closed Dere-Wah closed 1 month ago

Dere-Wah commented 1 month ago

I am trying to connect to a PostgreSQL database, but when doing so, I am getting the SQLException "No suitable driver".

I am using this syntax:

set {piazza::db} to the database "postgresql://:/?user=&password=&ssl=false" but when I execute any statement on the db this error is printed in console:

 [09:39:51 WARN]: java.util.concurrent.CompletionException: java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=jdbc:postgresql://MY-IP:PORT/postgres?user=USERNAME&password=<masked>&ssl=false
[09:39:51 INFO]: [Skript] Successfully reloaded db.sk. (49ms)
[09:39:51 WARN]:        at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315)
[09:39:51 WARN]:        at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320)
[09:39:51 WARN]:        at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1770)
[09:39:51 WARN]:        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
[09:39:51 WARN]:        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
[09:39:51 WARN]:        at java.base/java.lang.Thread.run(Thread.java:1570)
[09:39:51 WARN]: Caused by: java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=jdbc:postgresql://MY-IP:PORT/postgres?user=USERNAME&password=<masked>&ssl=false
[09:39:51 WARN]:        at Skcrew-patch.jar//com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:114)
[09:39:51 WARN]:        at Skcrew-patch.jar//com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:331)
[09:39:51 WARN]:        at Skcrew-patch.jar//com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:114)
[09:39:51 WARN]:        at Skcrew-patch.jar//com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:108)
[09:39:51 WARN]:        at Skcrew-patch.jar//com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
[09:39:51 WARN]:        at Skcrew-patch.jar//com.lotzy.skcrew.spigot.sql.SqlUtil.executeStatement(SqlUtil.java:40)
[09:39:51 WARN]:        at Skcrew-patch.jar//com.lotzy.skcrew.spigot.sql.effects.EffAsyncExecuteStatement.lambda$execute$0(EffAsyncExecuteStatement.java:63)
[09:39:51 WARN]:        at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
[09:39:51 WARN]:        ... 3 more
[09:39:51 WARN]: Caused by: java.sql.SQLException: No suitable driver
[09:39:51 WARN]:        at java.sql/java.sql.DriverManager.getDriver(DriverManager.java:300)
[09:39:51 WARN]:        at Skcrew-patch.jar//com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:106)
[09:39:51 WARN]:        ... 10 more

Even after going through the Skript-DB documentation, and seeing this:

image

I saw that I had to change the default driver to point at a PostgreSQL db driver. From an old issue on skript-db: https://git.limework.net/Limework/skript-db/issues/14

the solution is shading the Driver directly into the jar. In skript-db this is actually done, but on the releases on this github repo I don't see the Driver in any place.

To test further I tried adding the driver myself in the path org.postgresql.Driver in the Skcrew jar but yet the same error appears when trying to connect to a PostgreSQL.

Lotzyprod commented 1 month ago

I am trying to connect to a PostgreSQL database, but when doing so, I am getting the SQLException "No suitable driver".

I am using this syntax:

set {piazza::db} to the database "postgresql://:/?user=&password=&ssl=false" but when I execute any statement on the db this error is printed in console:

[09:39:51 WARN]: java.util.concurrent.CompletionException: java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=jdbc:postgresql://MY-IP:PORT/postgres?user=USERNAME&password=<masked>&ssl=false
[09:39:51 INFO]: [Skript] Successfully reloaded db.sk. (49ms)
[09:39:51 WARN]:        at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315)
[09:39:51 WARN]:        at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320)
[09:39:51 WARN]:        at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1770)
[09:39:51 WARN]:        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
[09:39:51 WARN]:        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
[09:39:51 WARN]:        at java.base/java.lang.Thread.run(Thread.java:1570)
[09:39:51 WARN]: Caused by: java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=jdbc:postgresql://MY-IP:PORT/postgres?user=USERNAME&password=<masked>&ssl=false
[09:39:51 WARN]:        at Skcrew-patch.jar//com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:114)
[09:39:51 WARN]:        at Skcrew-patch.jar//com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:331)
[09:39:51 WARN]:        at Skcrew-patch.jar//com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:114)
[09:39:51 WARN]:        at Skcrew-patch.jar//com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:108)
[09:39:51 WARN]:        at Skcrew-patch.jar//com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
[09:39:51 WARN]:        at Skcrew-patch.jar//com.lotzy.skcrew.spigot.sql.SqlUtil.executeStatement(SqlUtil.java:40)
[09:39:51 WARN]:        at Skcrew-patch.jar//com.lotzy.skcrew.spigot.sql.effects.EffAsyncExecuteStatement.lambda$execute$0(EffAsyncExecuteStatement.java:63)
[09:39:51 WARN]:        at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
[09:39:51 WARN]:        ... 3 more
[09:39:51 WARN]: Caused by: java.sql.SQLException: No suitable driver
[09:39:51 WARN]:        at java.sql/java.sql.DriverManager.getDriver(DriverManager.java:300)
[09:39:51 WARN]:        at Skcrew-patch.jar//com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:106)
[09:39:51 WARN]:        ... 10 more

Even after going through the Skript-DB documentation, and seeing this:

image

I saw that I had to change the default driver to point at a PostgreSQL db driver. From an old issue on skript-db: https://git.limework.net/Limework/skript-db/issues/14

the solution is shading the Driver directly into the jar. In skript-db this is actually done, but on the releases on this github repo I don't see the Driver in any place.

To test further I tried adding the driver myself in the path org.postgresql.Driver in the Skcrew jar but yet the same error appears when trying to connect to a PostgreSQL.

Yea, thanks for the issue. Added the driver, I'll release it a bit later (there's another problem with the packets module)

Dere-Wah commented 1 month ago

Thanks ;D Just to be clear, adding the driver to the path did not fix the issue when I did it on my own, editing the .jar of Skcrew.

Lotzyprod commented 1 month ago

Most likely you did everything correctly, the problem was that even the value from the config was read incorrectly. But I fixed everything, now in general, in most cases there is no need to think about the driver, unless of course there is some very specific DBMS

Thanks ;D Just to be clear, adding the driver to the path did not fix the issue when I did it on my own, editing the .jar of Skcrew.