How can i connect to the JDBC resource from inside a Java plugin? (Confluence)

I need to connect to the Confluence databases to the extent where i can execute SQL queries and get results.

When attempting to create a JDBC connection in my user search plugin, I get the following error

java.sql.SQLException: No suitable driver found for jdbc/renderStatsDS

This is (i believe) because Confluence uses a resource on the server to connect automatically to it's database.

I've found the resource at opt/atlassian/confluence/conf/server.xml

<Resource   name="jdbc/renderStatsDS"
    auth="Container"
    type="javax.sql.DataSource"
    driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://aveley.dhcp.dneg.com/renderstats?autoReconnect=true"
    username="safety"
    password="safety"
    maxActive="25"
    maxIdle="5"
    maxWait="10000"
/>

Does anyone know how to access this resource?

Alternatively if anyone has any code they could share that has connected to the confluence database and been able to execute SQL via some other method, that would obviously be very helpful to me too.

Cheers, Matt

2 answers

1 accepted

Accepted Answer
1 vote
David Simpson Community Champion Sep 24, 2012

Matt, check my answer to How to access external database through Confluence Plugin earlier today :)

It's almost an identical question. Also, don't forget to add your driver jar to <CATALINA_HOME>\common\lib

My colleague had actually jsut stood up from his seat to come and tell me he'd found out how to do this as I was looking at your response haha.

Thanks a lot for the reply, I'm surprised i didn't find that toher post from this morning when i was searching here, maybe it hadn't been cached yet or something.

Thanks again!

Hi David

Is it possible to create a datasource from the Confluence database (configured in confluence.cfg.xml). I know it can be done by adding another entry in server.xml (duplicate) but if I want to ship my plugin to users, they will need to do this manually and I don't want them too.

Cheers

Hi, you need to use JNDI to access this resource.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted 5 hours ago in Featured Groups

Tuesday tips & tricks: What is the Atlassian Community?

It's officially Tuesday, which means it's officially time for another tip to help you better navigate this space we call the Atlassian Community. 😄 I got a great question from community member, Sa...

15 views 0 1
View post

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you