ORA-01810: 格式代码出现两次:jdbctemplate
ORA-01810: format code appears twice : jdbctemplate
我正在使用 jdbctemplate 检查一些日期和查询,但出现以下错误。
// creating a LocalDate object with specific date & time
LocalDate date = LocalDate.of(LocalDate.now().getYear(), LocalDate.now().getMonth(), LocalDate.now().getDayOfMonth());
System.out.println("date $$$$$$$$$$$" +date);
LocalDateTime datetime = date.atTime(LocalTime.MAX);
System.out.println("datetime " +datetime);
// is not required since above steps is the same.
datetime.withHour(23).withMinute(59).withSecond(59);
System.out.println("datetime with " +datetime);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh24:mm:ss");
System.out.println("formatter" +datetime.format(formatter));
return jdbcTemplate.queryForObject("SELECT COUNT(*) FROM test where status in ('ACTIVE','ACTIVE_P') AND CREATED<TO_dATE('"+datetime.format(formatter)+"','yyyy-MM-dd hh24:mm:ss')",Integer.class);
这是输出
date $$$$$$$$$$17-08-20
datetime 2017-08-20T23:59:59.999999999
datetime with 2017-08-20T23:59:59.999999999
formatter2017-08-20 1124:59:59
2017-08-20 01:53:00.029 INFO 12604 --- [pool-1-thread-1] com.zaxxer.hikari.HikariDataSource : hikari-subscription - Started.
2017-08-20 01:53:00.034 WARN 12604 --- [pool-1-thread-1] com.zaxxer.hikari.util.DriverDataSource : Registered driver with driverClassName=oracle.jdbc.driver.OracleDriver was not found, trying direct instantiation.
2017-08-20 01:53:00.949 INFO 12604 --- [pool-1-thread-1] com.zaxxer.hikari.pool.PoolBase : hikari-subscription - Driver does not support get/set network timeout for connections. (oracle.jdbc.driver.T4CConnection.getNetworkTimeout()I)
2017-08-20 01:53:02.190 INFO 12604 --- [pool-1-thread-1] o.s.b.f.xml.XmlBeanDefinitionReader : Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
2017-08-20 01:53:02.274 INFO 12604 --- [pool-1-thread-1] o.s.jdbc.support.SQLErrorCodesFactory : SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase, Hana]
2017-08-20 01:53:02.283 ERROR 12604 --- [pool-1-thread-1] o.s.s.s.TaskUtils$LoggingErrorHandler : Unexpected error occurred in scheduled task.
org.springframework.dao.DataIntegrityViolationException: StatementCallback; SQL [SELECT COUNT(*) FROM test where status in ('ACTIVE','ACTIVE_P') AND CREATED<TO_dATE('2017-08-20 1124:59:59','yyyy-MM-dd hh24:mm:ss')]; ORA-01810: format code appears twice
; nested exception is java.sql.SQLDataException: ORA-01810: format code appears twice
at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:82) ~[spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) ~[spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:419) ~[spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:474) ~[spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:484) ~[spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:494) ~[spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:500) ~[spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
我看到在日志中查询被打印为
AND CREATED<TO_dATE('2017-08-20 1124:59:59','yyyy-MM-dd hh24:mm:ss')
1124,我认为这是问题所在,但无论我做什么,我都无法删除那个 11。
24 小时格式为 Java 和 HH
,使用:
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
1) 您必须将 :mm: 更改为 :mi:,格式为 mask:
SELECT TO_DATE('2017-08-20 23:59:59','yyyy-MM-dd hh24:mi:ss') FROM DUAL
2) 之后您必须编辑您的营业时间部分。
我正在使用 jdbctemplate 检查一些日期和查询,但出现以下错误。
// creating a LocalDate object with specific date & time
LocalDate date = LocalDate.of(LocalDate.now().getYear(), LocalDate.now().getMonth(), LocalDate.now().getDayOfMonth());
System.out.println("date $$$$$$$$$$$" +date);
LocalDateTime datetime = date.atTime(LocalTime.MAX);
System.out.println("datetime " +datetime);
// is not required since above steps is the same.
datetime.withHour(23).withMinute(59).withSecond(59);
System.out.println("datetime with " +datetime);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh24:mm:ss");
System.out.println("formatter" +datetime.format(formatter));
return jdbcTemplate.queryForObject("SELECT COUNT(*) FROM test where status in ('ACTIVE','ACTIVE_P') AND CREATED<TO_dATE('"+datetime.format(formatter)+"','yyyy-MM-dd hh24:mm:ss')",Integer.class);
这是输出
date $$$$$$$$$$17-08-20
datetime 2017-08-20T23:59:59.999999999
datetime with 2017-08-20T23:59:59.999999999
formatter2017-08-20 1124:59:59
2017-08-20 01:53:00.029 INFO 12604 --- [pool-1-thread-1] com.zaxxer.hikari.HikariDataSource : hikari-subscription - Started.
2017-08-20 01:53:00.034 WARN 12604 --- [pool-1-thread-1] com.zaxxer.hikari.util.DriverDataSource : Registered driver with driverClassName=oracle.jdbc.driver.OracleDriver was not found, trying direct instantiation.
2017-08-20 01:53:00.949 INFO 12604 --- [pool-1-thread-1] com.zaxxer.hikari.pool.PoolBase : hikari-subscription - Driver does not support get/set network timeout for connections. (oracle.jdbc.driver.T4CConnection.getNetworkTimeout()I)
2017-08-20 01:53:02.190 INFO 12604 --- [pool-1-thread-1] o.s.b.f.xml.XmlBeanDefinitionReader : Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
2017-08-20 01:53:02.274 INFO 12604 --- [pool-1-thread-1] o.s.jdbc.support.SQLErrorCodesFactory : SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase, Hana]
2017-08-20 01:53:02.283 ERROR 12604 --- [pool-1-thread-1] o.s.s.s.TaskUtils$LoggingErrorHandler : Unexpected error occurred in scheduled task.
org.springframework.dao.DataIntegrityViolationException: StatementCallback; SQL [SELECT COUNT(*) FROM test where status in ('ACTIVE','ACTIVE_P') AND CREATED<TO_dATE('2017-08-20 1124:59:59','yyyy-MM-dd hh24:mm:ss')]; ORA-01810: format code appears twice
; nested exception is java.sql.SQLDataException: ORA-01810: format code appears twice
at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:82) ~[spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) ~[spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:419) ~[spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:474) ~[spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:484) ~[spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:494) ~[spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:500) ~[spring-jdbc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
我看到在日志中查询被打印为
AND CREATED<TO_dATE('2017-08-20 1124:59:59','yyyy-MM-dd hh24:mm:ss')
1124,我认为这是问题所在,但无论我做什么,我都无法删除那个 11。
24 小时格式为 Java 和 HH
,使用:
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
1) 您必须将 :mm: 更改为 :mi:,格式为 mask:
SELECT TO_DATE('2017-08-20 23:59:59','yyyy-MM-dd hh24:mi:ss') FROM DUAL
2) 之后您必须编辑您的营业时间部分。