我試圖做一個JDBC的測試。我從schema.sql文件創建表,我從data.sql文件插入數據到表中。當我試圖做一個測試,我得到一個錯誤:SQLDataException:從HSQLDB無效的日期時間格式
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'
所以,在文檔中是關於日期格式的例子。 這裏是我的我的文檔-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');
什麼樣的列類型是'documents.created'和'documents.modified'? – Benvorth
創建日期時間NOT NULL, 修改日期時間NOT NULL, – Algeroth