JDBC Driver not available

Jan Kueck March 4, 2015

Hello everyone,

I have a problem. I develop a Confluence Macro. I want to conenct to an external database and I can not establish a connection via ActiveObjects. If I use the following way to conenct to an database I get an ClassNotFoundException. (com.mysql.jdbc.Driver)

EntityManager entityManager = EntityManagerBuilder
	.url("jdbc:mysql://localhost/confluence")
    .username("root")
    .password("")
    .auto()
    .build();

 

If I use this way I can nonnect to an database but can not use the ActiveObjects framework.

Driver driver = this.loadDriver("com.mysql.jdbc.Driver");
            
Properties props = new Properties();
props.setProperty("user", "root");
props.setProperty("password", "");
String url = "jdbc:mysql://localhost/confluecne";
Connection connection = driver.connect(url, props);

private Driver loadDriver(final String driverName) throws SQLException {
	try {
		final Class clazz = ClassLoaderUtils.loadClass(driverName,CargoSoftCustomerMacro.class);
            System.out.println("Load new Class..");
            return (Driver) clazz.newInstance();
        } catch (ClassNotFoundException e) {
            throw new SQLException("JDBC driver class not found: " + driverName, e);
        } catch (Exception e) {
            throw new SQLException("Cannot instantiate JDBC driver class " + driverName + ": " + e.getMessage(), e);
        }
    }

I add the com.mysql.jdbc.Driver in my pom.xml and in my classpath from the project. I think the second way works because the right classloader loads the driver and by the first way there are problems beacuase the wrong classloader load the driver and can not find them.

Can anyone help me with this problem?

Thanks for replies! smile

 

Greetz

Jan

 

 

3 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
jacob delddd July 26, 2018

how did you solve this problem?

0 votes
Alex Medved _ConfiForms_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 7, 2015

Take a look at this page, quite large and complex, but worth reading...

 https://developer.atlassian.com/docs/getting-started/working-with-the-pom/managing-dependencies 

{quote} In the past, you could add a JAR file to the WEB-INF/lib directory and make it available to all plugins, as well as the product itself. This no longer works, as the plugin system doesn't know about any code in the product beyond what it's been told to use; placing random JARs in WEB-INF/lib or class files in WEB-INF/classes will not make them available in the system bundle. {quote}

Took this from this discussion https://answers.atlassian.com/questions/11991634

Jan Kueck March 10, 2015

I read the text and I think I understand the function. I have add a dependency in my pom wich includes the mysql driver and scope compile. There is also a classnotfoundexception during call my plugin. The driver is not in my plugin classpath I think. Because when I call the ActiveObjects EntityManager I get the exception. I do not understand the problem. Hope for help! :) Greetz

0 votes
Ibrahim hussam March 4, 2015

h, 

I think you need to add a dependency in pom.xml

 

<dependency>

            <groupId>mysql</groupId>

            <artifactId>mysql-connector-java</artifactId>

            <version>5.1.12</version>

            <scope>install</scope>

        </dependency>

 

and you should have the jar file in your target folder.

target\classes\META-INF\lib

 

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events