I'm using Ready API 1.4.0 and I have tried this groovy code to connect to postgresql.
import groovy.sql.Sql
import java.sql.Driver
def driver = Class.forName('org.postgresql.Driver').newInstance() as Driver
def props = new Properties()
props.setProperty("DB_user", "user")
props.setProperty("DB_password", "user")
def conn = driver.connect("jdbc:postgresql://localhost:54320/database_name", props)
def sql = new Sql(conn)
try {
sql.eachRow("select * from user") {
log.debug(it)
}
} finally {
sql.close()
conn.close()
}
Then I received this error:
java.lang.ClassNotFoundException:org.postgresql.Driver at line:4
I added this jar lib and in bin/ext postgresql-9.4-1205.jdbc42.jar
Any help, please? Thank you.
Try use Grape to get your PostgreSQL driver.
@GrabConfig(systemClassLoader=true)
@Grab(group='org.postgresql', module='postgresql', version='9.4-1205-jdbc42')
See http://docs.groovy-lang.org/latest/html/documentation/grape.html#Grape-JDBCDrivers
I had the same issue. So manually download the postgres driver and loaded into Jenkins master server java's lib directory.
PostgreSQL JDBC 4.2 Driver, 42.2.14 https://jdbc.postgresql.org/download.html
After restarting Jenkins service, its working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With