java - HSQLDB, LocalDateTime, JdbcTemplate -
i'm trying use hsqldb, spring jdbc template. works fine, until use java 8's localdatetime class.
i have code:
import org.hsqldb.jdbc.jdbcdatasource; import org.springframework.core.io.classpathresource; import org.springframework.core.io.resource; import org.springframework.jdbc.core.jdbctemplate; import org.springframework.jdbc.datasource.init.resourcedatabasepopulator; import java.time.localdatetime; public class test { public static void main(string[] args) throws exception { jdbcdatasource datasource = new jdbcdatasource(); datasource.setuser("sa"); datasource.setpassword(""); datasource.seturl("jdbc:hsqldb:mem:db"); resource resource = new classpathresource("/test.sql"); resourcedatabasepopulator databasepopulator = new resourcedatabasepopulator(resource); databasepopulator.execute(datasource); jdbctemplate template = new jdbctemplate(datasource); template.update("insert test values (?)", localdatetime.now()); } }
the script looks this:
create table test ( datetime datetime not null, );
when try run it, i'll exception:
org.hsqldb.hsqlexception: incompatible data type in conversion
in app backend use localdatetime. how can make work?
you should able work around problem converting localdatetime
java.sql.timestamp
using timestamp.valueof()
:
jdbctemplate template = new jdbctemplate(datasource); template.update("insert test values (?)", timestamp.valueof(localdatetime.now()));
Comments
Post a Comment