Application name in JDBC url using c3p0

2019-08-02 17:12发布

问题:

I want my application be registered with particular name in DB.

I have configured CAS application. CAS is based on Spring framework. As connection manager it uses c3p0. As RDBMS I use PostgreSQL.

In jdbcUrl I set the following:

jdbc:postgresql://localhost:5432/dbname?ApplicationName=CAS_TEST

in spring xml config my dataSource looks like:

<bean id="dataSource"
      class="com.mchange.v2.c3p0.ComboPooledDataSource"
      p:driverClass="org.postgresql.Driver"
      p:jdbcUrl="${my.db.url}"
      p:user="${my.db.user}"
      p:password="${my.db.password}" />

The same approach with jdbcUrl and application name I use in Grails applications and everything is fine, but Grails uses another connection manager and I suppose c3p0 cuts url or something.

Does anyone have similar experience or know how to deal with application name in this case.

Thanks in advance.

回答1:

Finally I've found where is a problem. It's not c3p0 issue. It was PostgreSQL driver issue, I've change it to the latest version and application name is appeared in the DB.

Not working driver dependency:

 <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.1-901.jdbc4</version>
 </dependency>

Working driver dependency

<dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.4.1209.jre7</version>
</dependency>