我有一个带有 glassfish 服务器并使用 EclipseLink (JPA 2.1) 的动态应用程序。我以前可以直接将jdbc配置放入persistence.xml
,没有任何问题。但现在它迫使我为 glassfish 创建一个数据源名称并将 jdbc 配置放入glassfish-resources.xml
文件中。
问题是我想将mysql的字符编码设置为utf8,因此,我在下面的url中使用了jdbc url:
jdbc:mysql://localhost:3306/fastfood?zeroDateTimeBehavior=convertToNull;&characterEncoding=UTF-8;
但我得到了这个例外:
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: The connection property 'zeroDateTimeBehavior' only accepts values of the form: 'exception', 'round' or 'convertToNull'. The value 'convertToNull;' is not in this set.
我想知道如何用&符号在url中添加多个参数?:D
我也不想创建 JNDI 数据源,而是手动将 jdbc 属性放在 persistence.xml 中,并确保我正确指定了 JDBC 驱动程序并将 MySQL JDBC 驱动程序添加到库中,但我收到错误消息:
“找不到合适的驱动程序”
glassfish-resource的完整内容如下:
<resources>
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="mysql_rootPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="serverName" value=""/>
<property name="User" value="root"/>
<property name="Password" value=""/>
<property name="URL" value="jdbc:mysql://localhost:3306/fastfood?zeroDateTimeBehavior=convertToNull;&characterEncoding=UTF-8;"/>
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" jndi-name="Fastfood" object-type="user" pool-name="mysql_rootPool"/>
</resources>