"java.lang.ClassNotFoundException: org.postgresql.Driver" How to implement PostgreSQL?

Hello everybody,

I have a problem with integrating PostgreSQL as my standard db for a Cuba application. This application has some entities and works fine on hsqldb. The entities were created on the hsqldb.

I read in the documentation that I only have to change the cuba.dbmsType in the context.xml. I did that and afterwards I got a message in the console of the studio. It says that the context.xml differs from the build.gradle and that I should change the values manually.

So I opened the build.gradle and changed the values of task createDb and task updateDb.


    task createDb(dependsOn: assembleDbScripts, description: 'Creates local database', type: CubaDbCreation) {
        dbms = 'postgres'
        dbmsVersion = 'null'
        host = 'localhost'
        dbName = 'fdmlgr'
        dbUser = 'postgres'
        dbPassword = 'postgres'
    }

    task updateDb(dependsOn: assembleDbScripts, description: 'Updates local database', type: CubaDbUpdate) {
        dbms = 'postgres'
        dbmsVersion = 'null'
        host = 'localhost'
        dbName = 'fdmlgr'
        dbUser = 'postgres'
        dbPassword = 'postgres'
    }
}

But I still get the same errors:
“org.postgresql.util.PSQLException: FATAL: Database fffdfdmlgrfffd doesnt exist” when creating the db scripts
and
"java.lang.ClassNotFoundException: org.postgresql.Driver" when I try to create a the database.

Then I recognized in the build.gradle that there is a variable called hsql which is used later in the dependencies. So I changed it too. I put in the actual postgesql jdbc driver: 'postgresql:postgresql:9.1-901.jdbc4’
renamed it to posgres and also in the dependencies section.

Am I missing something?

Thank you in advance for your time and your help.

Greetings Clemens

Hi Clemens,
The simplest way to switch to PostgreSQL is to use Studio: just open Project properties and change database settings. After saving the settings, generate DB scripts again - they will be stored separately from HSQL scripts.

If you get “org.postgresql.util.PSQLException: FATAL: Database fffdfdmlgrfffd doesnt exist”, try to execute “Run > Create database” or “gradle createDb” before generating scripts (there is an issue about this in the current Studio version).

If you get “java.lang.ClassNotFoundException: org.postgresql.Driver” when creating or updating databbase in Studio or by Gradle, then something is wrong with your dependency on Postgres driver in build.gradle. If you get this exception when running the app server, probably the driver JAR is not in tomcat/lib (is is copied there when you deploy by Studio).

Just in case: if you cannot open your project in Studio because it is too large for the free version, create a sample project in Studio, add Git integration, and play with changing databases. Then Git will allow you to see what have been changed by Studio.

1 Like

Hi Konstantin,

thank you very much for your reply. I have tried it now through the studio and it works fine. I got this error “org.postgresql.util.PSQLException: FATAL: Database fffdfdmlgrfffd doesnt exist”, but “Run>Create database” worked and after that I could generate my scripts.

I coppied the .jar in the tomcat/lib because of that I was wondering why the “java.lang.ClassNotFoundException: org.postgresql.Driver” occurs. But the way through the studio works fine and I will take that in the future.

The size of the project doesn´t matter, because we have two licenses to work with.

Thank you very much again. I appreciate your help.