We help IT Professionals succeed at work.

How to call Stored procedure with datetime as a parameter in Spring JDBC?

heyday2004
heyday2004 asked
on
I want to use Sprng JDBC to get resultset based on datetime as the input parameter. Any good sample code on calling stored procedures with datetime parameter (and better have mysql sample procedure too) to return a resultset using Spring SimpleJdbcCall? BTW, in Spring documentation, there is an example that call the stored proc without any parameter. Thanks.
Comment
Watch Question

Top Expert 2016
Commented:
Use
cs.setTimestamp(1, java.sql.Timestamp.valueOf("2008-03-28 23:08:46"));

Open in new window

Author

Commented:
are there more general/detailed/complete examples? Thanks a lot.
Top Expert 2016
Commented:

Author

Commented:
Thanks. I'm using MySQL. Any related examples?
Top Expert 2016
Commented:
Exactly the same principle - just use a different DataSource
Top Expert 2016
Commented:

Author

Commented:
Thanks but this is not exactly what I wanted. What I wanted is how to use SimpleJdbcCall (simpleJdbcTemplate) to call stored procedure. It will use withProcedureName to get the procedure, but I could not find how to use input parameter in this case. Thanks for any help.
Java Developer
Top Expert 2010
Commented:
try something like this:


call = new SimpleJdbcCall(dataSource).withProcedureName("my_proc");
SqlParameterSource in = new MapSqlParameterSource().addValue("in_date", date);
Map out = call.execute(in);
Mick BarryJava Developer
Top Expert 2010

Commented:
for anyone else reading this question, all the assisted comments are actually wrong and are totally unrelated to the question asked

heyday2004,

Don't accept comments that are obviously wrong, it only confuses others reading the question in the future