我正在调用存储过程。这是我的Spring设置和类
Spring setup
@Configuration
@PropertySource(value = { "classpath:database/jdbc.properties" })
@EnableTransactionManagement
public class PersistenceConfig {
@Autowired
private Environment env;
@Bean(destroyMethod = "close")
public DataSource mySqlDataSource() {
BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName(env.getProperty("jdbc.mysql.driverClassName"));
...
return dataSource;
}
@Bean
public JdbcTemplate mySqlJdbcTemplate() {
JdbcTemplate jdbcTemplate = new JdbcTemplate(mySqlDataSource());
return jdbcTemplate;
}
}
Dao班
@Repository
public class MySQLCourseRenewalDaoImpl implements MySQLCourseRenewalDao {
@Inject
private JdbcTemplate mySqlJdbcTemplate;
@Override
public void callStoredProcedure(String storedProcedureName, Map<String, Object> inParamMap) throws Exception {
SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(mySqlJdbcTemplate).withProcedureName(storedProcedureName);
SqlParameterSource in = new MapSqlParameterSource(inParamMap);
Map<String, Object> simpleJdbcCallResult = simpleJdbcCall.execute(in);
}
}
在inParamMap
我正在输入一个像
LocalDateTime iUserCourseCourseCompletionDate = userCourse.getCourseCompletionDate();
inParamMap.put("iUserCourseCourseCompletionDate", Timestamp.valueOf(iUserCourseCourseCompletionDate));
如果我删除Timestamp.valueOf
并仅使用inParamMap.put("iUserCourseCourseCompletionDate",iUserCourseCourseCompletionDate);
。然后当存储过程运行时,我得到以下异常
CallableStatementCallback; SQL [{call usp_processCourseRenewal(?, ?, ?, )}]; Cannot convert class java.time.LocalDateTime to SQL type requested due to java.lang.ClassCastException - java.time.LocalDateTime cannot be cast to java.util.Date; nested exception is java.sql.SQLException: Cannot convert class java.time.LocalDateTime to SQL type requested due to java.lang.ClassCastException - java.time.LocalDateTime cannot be cast to java.util.Date
使用TimeStamp和java.util.Date存储过程可以正常工作。是否有任何方式存储过程调用也适用于Java8日期时间API。
我正在使用spring 4.2.2
由于