到目前为止,我尝试过
jdbcTemplate.update("INSERT INTO INFO (id, my_date)
"VALUES(?, ?)", 1, "sysdate");
还尝试通过仅使用地图对namedParameterJdbcTemplate进行操作。
Map namedParameters = new HashMap();
namedParameters.put("id", 1);
namedParameters.put("my_date", "sysdate");
namedParameterJdbcTemplate.update("INSERT INTO INFO (id, my_date)
"VALUES(:id, :my_date)",namedParameters);
尝试以上所有方法后,异常不在下方
org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [INSERT INTO INFO (id, my_date)
"VALUES(?, ?)]; ORA-01858: a non-numeric character was found where a numeric was expected
; nested exception is java.sql.SQLDataException: ORA-01858: a non-numeric character was found where a numeric was expected
at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:82) ~[spring-jdbc-4.3.17.RELEASE.jar:4.3.17.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) ~[spring-jdbc-4.3.17.RELEASE.jar:4.3.17.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:82) ~[spring-jdbc-4.3.17.RELEASE.jar:4.3.17.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:655) ~[spring-jdbc-4.3.17.RELEASE.jar:4.3.17.RELEASE]
找到了这个链接,他们声称可以这样做。我不知道怎么做,除非我做错了什么。有什么建议吗? http://forum.spring.io/forum/spring-projects/data/99020-is-it-possible-to-use-oracle-s-sysdate-with-simplejdbcinsert
答案 0 :(得分:0)
作为替代方案,您可以使用Java中可用的当前时间戳:
Timestamp sysdate = new Timestamp(System.currentTimeMillis());
Map namedParameters = new HashMap();
namedParameters.put("id", 1);
namedParameters.put("my_date", sysdate);
答案 1 :(得分:0)
您的Java代码不知道sysdate
是什么,它是Oracle数据库中的特定变量。按照与Tim的回答类似的方式,我将在您的代码中指定一个 java 变量,尽管其格式与您的第二次尝试类似:
Map<String, Object> namedParameters = new HashMap<String, Object>();
namedParameters.put("id", 1);
namedParameters.put("my_date", new Date());//java.util.Date
jdbcTemplate.update("INSERT INTO info (id, my_date) VALUES (:id, :my_date)", namedParameters);