gpt4 book ai didi

java - SQLDataException : invalid datetime format from HSQLDB

转载 作者:行者123 更新时间:2023-11-29 01:54:51 25 4
gpt4 key购买 nike

我正在尝试对 JDBC 进行测试。我正在从 schema.sql 文件创建表,并将数据插入到 data.sql 文件的表中。当我尝试进行测试时,出现错误:

java.sql.SQLDataException: data exception: invalid datetime format

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'engine' defined in class path resource [META-INF/spring/mydocuments-jdbc-context.xml]: Cannot resolve reference to bean 'documentDAO' while setting bean property 'documentDAO'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'documentDAO' defined in class path resource [META-INF/spring/mydocuments-jdbc-context.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: java.sql.SQLDataException: data exception: invalid datetime format

我不明白为什么,因为我的日期格式是正确的:例如

'2014-02-24 11:52'

因此,在文档中是关于日期格式的相同示例。这是我的 mydocuments-jdbc-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">


<context:property-placeholder location="jdbc.properties"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>

<bean id="engine" class="spring.service.SearchEngineService">
<property name="documentDAO" ref="documentDAO"/>
</bean>

<bean id="documentDAO" class="spring.data.DocumentRepository" init-method="initialize">
<property name="dataSource" ref="dataSource"/>
<property name="schema" value="classpath:META-INF/data/schema.sql"/>
<property name="data" value="classpath:META-INF/data/data.sql"/>
<property name="queryAll">
<value>
select d.documentId, d.name, d.location, d.description as doc_desc, d.typeId, d.created, d.modified,
t.name as type_name, t.description as type_desc, t.extension from documents d
join types t
on d.typeId = t.typeId
</value>
</property>
</bean>

</beans>

这是我的 data.sql 文件

INSERT INTO types (typeId, name, description, extension) VALUES ('41e2d211-6396-4f23-9690-77bc2820d84b', 'PDF', 'Portable Document Format', '.pdf');
INSERT INTO documents (documentId, name, location, description, typeId, created, modified) VALUES ('431cddbf-f3c0-4076-8c1c-564e7dce16c9', 'Pro Spring Security Book', 'http://www.apress.com/9781430248187', 'Excellent Book', '4980d2e4-a424-4ff4-a0b2-476039682f43', '2014-02-14', '2014-02-20');

最佳答案

尝试将您的 data.sql 文件修改为有效的日期时间值,而不仅仅是日期值:

INSERT INTO documents (
documentId, name, location, description, typeId, created, modified)
VALUES ('431cddbf-f3c0-4076-8c1c-564e7dce16c9', 'Pro Spring Security Book',
'http://www.apress.com/9781430248187',
'Excellent Book', '4980d2e4-a424-4ff4-a0b2-476039682f43',
'2014-02-14 00:00:00', '2014-02-20 00:00:00'
);

关于java - SQLDataException : invalid datetime format from HSQLDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32103522/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com