PostgreSQL Driver

Hi everyone

The PostgreSQL driver that Lucee has on board is older.

Is there a way to programmatically update it on boot without opening admin?

Or something usefull like this:

this.datasources["myDatasource"] = {
       type = "postgresql",
       useClass="/webroot/libs/new-postgres.driver.jar
};

I’m using CommandBox for the deploy.

Many many thanks.

OS: Linux
Java Version: 11.0.11 AdoptOpenJDK
Lucee Version: 5.3.8.201

command box is nice, but in the end pure CFENGINE is the way to go.

Look at this post,

You could write a bit of code to dynamically create a file to create the data source.

Sorry Terry but I didn’t understand how adding the datasource to the Application.cfc (as I already do) could solve my problem.

I read the post you indicated, so in my Application.cfc I should write:

this.datasources["myDatasource"] = {
    class: 'org.postgresql.Driver'
    , bundleName: 'org.postgresql.jdbc'
    , bundleVersion: '42.2.20 '<- **the version I need**
}

but to use the 42.2.0 version of the driver I should have to update it from the Lucee admin.
It’s not so?

I would like to update the driver programmatically, without using the admin.

Thanks for your patience.

The problem is, that the driver is an extension that doesn’t come with Lucee per se, thus, for doing it programatically, I think you will need to download it via cfhttp, store it to the lucee servers extension directory and restart Tomcat. Another approach would be to use Lucee Environment Variables or System Properties. But as far I can remember, you’d need to redeploy the complete Lucee server context (you may need to wipe out the server context first), but I’m not really sure.

1 Like

You could do something like chttp to download the file or cfcurl or cfexcute a bash script that fires off wget.

<cfhttp method="get" url="https://jdbc.postgresql.org/download/postgresql-42.3.4.jar">
<cfset fileName = listlast(cfhttp["responseHeader"]["content-disposition"],";=")>
<cffile action="write" file="/path/to/my/driver/place/#fileName#" output="#cfhttp.FileContent#">

Now you have the file, now you have to figure out after you get the file how to add it someplace you need it, and then add the file to lucee. You could fire off cfexcute that runs a bash or powershell script that restarts lucee and places the file where you need it, you could just place the driver in your needed application path and just directly reference the jar file from coldfusion.

this typically would go in the web-inf/lib directory.

Then code wise you can invoke your custom loaded jar

<cfset javaloader = CreateObject("component", "javaloader.JavaLoader")
1 Like

@Terry_Whitney nice idea!!!

@Roberto_Marzialetti Because you are using CommandBox, you could also use CommandBox env variables, and set LUCEE_EXTENSIONS=671B01B8-B3B3-42B9-AC055A356BED5281 ;version=42.2.20

Then stop the server, forget the server and restart. However, that could take some time, depending to the size of your app and your setup.

However, I like @Terry_Whitney approach very much, because you could load the libary on the fly, maybe also with @Julian_Halliwell s awesome osgi loader

1 Like

Thanks @andreas @Terry_Whitney!

Now the picture is complete.
I’ll try the OSGI Loader because I don’t want to have to restart Tomcat/Lucee.

Thank you so much guys!

2 Likes