SQLDataException: invalid datetime format from HSQLDB

11,329

Try to modify your data.sql file to a valid datetime value, not just date-values:

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'
);
Share:
11,329
Algeroth
Author by

Algeroth

Updated on June 14, 2022

Comments

  • Algeroth
    Algeroth almost 2 years

    I'm trying to make a test of JDBC. I'm creating tables from schema.sql file and I'm inserting data into tables from data.sql file. When I'm trying to make a test, I get an error:

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

    and

    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
    

    I don't understand why, because my date format is correct: for example

    '2014-02-24 11:52'
    

    so, in documentation is the same example about date format. Here's my 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>
    

    and here's my data.sql file

    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');