Question

I'm trying to find the best way to create a dataSource in Spring for connecting to a Google Cloud SQL instance.

I'm currently using:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.GoogleDriver" />
    <property name="url" value="jdbc:google:mysql://myappid:instanceId/mydb?user=myuser" />
    <property name="username" value="myuser" />
    <property name="password" value="mypassword" />
</bean>

However, I'm a little concerned about using the DriverManagerDataSource provided by Spring as it's documentation says it creates a new connection for every call.

Before migrating over to App Engine I was using a connection pool called BoneCP - however it uses classes that are restricted by App Engine. Is there a connection pool or some other data source class that is recommended to be used with Google Cloud SQL?

Était-ce utile?

La solution

Try c3p0 or commons-dbcp. They both implement javax.sql.Datasource which is whitelisted by app-engine.

Example on commons-dbcp:

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.GoogleDriver" />
    <property name="url" value="jdbc:google:mysql://myappid:instanceId/mydb?user=myuser" />
    <property name="username" value="myuser" />
    <property name="password" value="mypassword" />
    <property name="validationQuery" value="SELECT 1"/>
</bean>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top