Mysql connection in the NodeModel

In my new node, I would like access to a Mysql database (from the NodeModel and from the NodeDialog). To do this, I want to use the Mysql driver already used in a DatabaseConnector node of my workflow.

Currently, I use this code :

String currentDriver = "C:/LOGICIELS/knime_2.4.0/mysql-connector-java-5.1.15-bin.jar";
DatabaseDriverLoader.loadDriver(new File(currentDriver));
String url = "jdbc:mysql://localhost:3306/mydatabase";
con = DriverManager.getConnection(url, "root", "root");

The Mysql connection works except when the DatabaseConnector node is already executed when KNIME is started : in this case the connection fails. I think it is because the DatabaseConnector do not "load" the driver since the DatabaseConnector is already executed...

Could you help me to solve this problem please.




I solved a similar problem by loading the the driver in the plugin activator class. This ensures that the driver is always loaded when the plugin is started.

It might also be a better idea to place the drivers jar file within the plugin such that it can be referenced as relative to the plugin path.

Hope that helps,