How to set zeroDateTimeBehavior on JNDI DataSource without using URL?
In this stackoverflow question the poster implies that you can set zeroDateTimeBehavior="convertToNull"
as an attribute on the <Resource>
tag.
Does anyone know if this should be possible? All the docs I've looked at say that you can only add this property on the database connection url.
I'm actually looking for a way to set this property on the DataSource from within the Spring context, so that we don't have to go around and update all our various environments, or risk losing property this should someone need to change the connection url.
A Spring configured DataSource makes it very easy:
开发者_如何学JAVA<bean id="propsDataSource" class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
<property name="url" value="${connection.url}"/>
<property name="user" value="${connection.username}"/>
<property name="password" value="${connection.password}"/>
<property name="zeroDateTimeBehavior" value="convertToNull"/>
</bean>
Does anyone know how to do this through a JNDI configured DataSource?
Thanks,
Hello the same answer of JoseK
But i have to put it in this way:
<Resource
name="jdbc/TamaJNDI"
auth="Container"
driverClassName="com.mysql.jdbc.Driver"
maxActive="15"
maxIdle="3"
name="jdbc/TamaJNDI"
password="*******"
type="javax.sql.DataSource"
url="jdbc:mysql://localhost:3306/OBRAS_CONTROL?zeroDateTimeBehavior=convertToNull"
username="TAMAWEB"/>
In my Tomcat context.xml file.
The docs at http://dev.mysql.com/doc/refman/5.1/en/connector-j-reference-configuration-properties.html state it should be passed on the URL.
Can you try if this works for you?
<ResourceParams name="jdbc/DataSourceName">
<parameter>
<name>zeroDateTimeBehavior</name>
<value>convertToNull</value>
</parameter>
</ResourceParams>
In case somebody needs this because they use
spring.cloud.gcp.sql.instance-connection-name=someProject:someRegion:someInstance
and have no URL to slap zeroDateTimeBehavior
onto, use:
spring.cloud.gcp.sql.instance-connection-name=someProject:someRegion:someInstance&zeroDateTimeBehavior=convertToNull
This works because internally that parameter gets appended after
jdbc:mysql://google/somaDatabase?socketFactory=com.google.cloud.sql.mysql.SocketFactory&cloudSqlInstance=
hence the desired result:
jdbc:mysql://google/somaDatabase?socketFactory=com.google.cloud.sql.mysql.SocketFactory&cloudSqlInstance=someProject:someRegion:someInstance&zeroDateTimeBehavior=convertToNull
Use inside jndi resource
connectionProperties="zeroDateTimeBehavior=convertToNull"
<Resource
name="jdbc/TamaJNDI"
auth="Container"
driverClassName="com.mysql.jdbc.Driver"
maxActive="15"
maxIdle="3"
name="jdbc/TamaJNDI"
password="*******"
type="javax.sql.DataSource"
url="jdbc:mysql://localhost:3306/OBRAS_CONTROL
username="TAMAWEB"
connectionProperties="zeroDateTimeBehavior=convertToNull"/>
精彩评论