Bonita 6.3.2 Studio - Postgres - No suitable DB driver found

1
0
-1

Hi there,

Bonita Studio 6.3.2, Java 1.7.0.67, Windows 8.1

I've been having real problems with this and it is infuriating - this should just work...!!!

I've created a small java connector to connect to a postgres database. All I ever get is

2014-08-24 09:31:34 org.bonitasoft
SEVERE: No suitable driver found for jdbc:postgresql://localhost:5432/dbname

I'm using the pre installed Bonita-connector-database-postgresql92-imple.1.0.10.jar

I've also tryed using the already installed postgresql-9.2-1002.jdbc.jar

but always with No suitable driver found for jdbc:postgresql://localhost:5432/dbname

I've tried copying the jars to

tomcat/lib and tomcat/lib/Bonita with NO success...

Just how do I get this to work?

Many thanks and best regards Seán

1 answer

1
0
-1
This one is the BEST answer!

OK,

apologies but after a lot of hassle I've managed to get a working sample of code for postgres on 6.3.3.

I've not experimented as yet but it could also affect mysql and other database drivers.

Windows So for Community Studio you have to place the postgresql-9.2-1002.jdbc4.jar file in {drive}:\BonitaBPMCommunity-6.3.3\workspace\tomcat\lib

that was already done from before...

the really important bit is just before the con = DriverManager.getConnection(url, user, password); statement where you have to use the Class.forName("org.postgresql.Driver"); statement which is something I've never had to use before.

The Class.forName (please see here)

*causes the class named X to be dynamically loaded (at runtime). A call to forName("X") causes the class named X to be initialized (i.e., JVM executes all its static block after class loading). Class.forName("X") returns the Class object associated with the "X" class. The returned Class object is not an instance of the "x" class itself.

Class.forName("X") loads the class if it not already loaded. The JVM keeps track of all the classes that have been previously loaded. This method uses the classloader of the class that invokes it. The "X" is the fully qualified name of the desired class.*

                try {
                        logger.info(thisTrace+"Bfore Load Class");
                                Class.forName("org.postgresql.Driver");
                        logger.info(thisTrace+"After Load Class: OK");
                        } catch (ClassNotFoundException e) {
                                // TODO Auto-generated catch block
                        logger.info(thisTrace+"After Load Class: ClassNotFoundException");
                        }

Not having the Class.forname causes a No suitable DB driver found error...

Here is the full working debug code (hardcoded example - not recommended):

/**
 *
 */

package org.mycompany.connector;

import org.bonitasoft.engine.connector.ConnectorException;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Logger;
/**
 *The connector execution will follow the steps
 * 1 - setInputParameters() --> the connector receives input parameters values
 * 2 - validateInputParameters() --> the connector can validate input parameters values
 * 3 - connect() --> the connector can establish a connection to a remote server (if necessary)
 * 4 - executeBusinessLogic() --> execute the connector
 * 5 - getOutputParameters() --> output are retrieved from connector
 * 6 - disconnect() --> the connector can close connection to remote server (if any)
 */

public class DbTestImpl extends AbstractDbTestImpl {

        @Override
        protected void executeBusinessLogic() throws ConnectorException{
                //Get access to the connector input parameters
       
                //TODO execute your business logic here

                String thisTrace = "SignalNextProcess: ";
                Logger logger= Logger.getLogger("org.bonitasoft");
                logger.info(thisTrace+"Start Trace");
                setOutput1(false);
               
                Connection con = null;
                PreparedStatement pst = null;
        ResultSet rs = null;
        String sql1 = null;
       
        String classpath = System.getProperty("java.class.path");
        logger.info(thisTrace+"classpath: "+classpath);

        String url = "jdbc:postgresql://localhost:5432/dbName";
        String user = "dbUser";
        String password = "dbPassword";
       
        try {
               
                logger.info(thisTrace+"Bfore Con");
                try {
                        logger.info(thisTrace+"Bfore Load Class");
                                Class.forName("org.postgresql.Driver");
                        logger.info(thisTrace+"After Load Class: OK");
                        } catch (ClassNotFoundException e) {
                                // TODO Auto-generated catch block
                        logger.info(thisTrace+"After Load Class: ClassNotFoundException");
                        }
            con = DriverManager.getConnection(url, user, password);
            DatabaseMetaData meta = con.getMetaData();
            logger.info(meta.getDatabaseProductName());
            logger.info(meta.getDatabaseProductVersion());
           
            setOutput1(true);
            logger.info(thisTrace+"After Con");
           
        } catch (SQLException ex) {
               
                logger.info(thisTrace+"Catch Con Error: SQLException");
                logger.info(ex.getMessage());

        } finally {
            try {
                if (rs != null) {
                        rs.close();
                }
                if (pst != null) {
                    pst.close();
                }
                if (con != null) {
                    con.close();
                }

            } catch (SQLException ex) {

                        logger.info(thisTrace+"Finally Con Error: SQLException");
                        logger.info(ex.getMessage());
                       
            }
        }      
       
                logger.info(thisTrace+"End Trace");

                //WARNING : Set the output of the connector execution. If outputs are not set, connector fails
                //setOutput1(output1);
       
         }

        @Override
        public void connect() throws ConnectorException{
                //[Optional] Open a connection to remote server
       
        }

        @Override
        public void disconnect() throws ConnectorException{
                //[Optional] Close connection to remote server
       
        }

}
Notifications