drdox
Contributor
Contributor

How do I construct JDBC connection strings in groovy?

Jump to solution
Hi All,

We want to access SQL/JDBC from with HQ's groovy plugin.

Obviously, we don't want to use a hard coded connection string.

1) Are there HQ properties that return the parameters required for create the connection string?

2) Normally, we'd use def sql = Sql.newInstance( ...

I'd much prefer an HQ method to obtain a fully configured SQL instance - say from a connection pool - does this exist?

Cheers,

-d-
0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal
Be sure to close that connection though:

Util.endConnection()

Charles


View solution in original post

0 Kudos
5 Replies
jtravis_hyperic
Hot Shot
Hot Shot
What type of DB are you using? Is it already represented in HQ? Is your plugin a snippet for the Groovy Console, or are you writing a full-featured HQU plugin (via hqu-gen-scaffold)?

Since HQ stores some of that information, it would be easiest to just use the connection information stored in the resource.

You can call getViewedResource().getConfig() from your controller to see what the configuration is for the viewed resource.
0 Kudos
drdox
Contributor
Contributor
We are using the built-in postgres database.

The plugin will need to connect to whatever database that HQ is using to store inventory & metrics.
0 Kudos
admin
Immortal
Immortal
Hey DrDox,

Piece of cake, then.

> import org.hyperic.hibernate.Util
>
> Connection c = Util.connection
>



-- Jon


On Apr 25, 2008, at 12:43 AM, drdox wrote:

> We are using the built-in postgres database.
>
> The plugin will need to connect to whatever database that HQ is
> using to store inventory & metrics.


0 Kudos
admin
Immortal
Immortal
Be sure to close that connection though:

Util.endConnection()

Charles


0 Kudos
drdox
Contributor
Contributor
Great stuff!!

Thank you both - I knew it had to be super-easy.
0 Kudos