How to not to lose the Time fields when passing a Date to Oracle Stored Proc using JDBC?

411 views

Problem: I had an SP to call which takes a param Date. I called this via JDBC with a valid Java Date, but it refused to save the time fields I supplied.

When preparing the SP for calling I did as follows,

mightySp('paramName',:paramName);

When supplying the parameter, I gave as follows,

tempPlsqlBlock.declareParameter(new SqlParameter("paramName", Types.DATE));

 

Solution: Instead of calling with param type Date, call with String and convert to date in the Java layer.

When preparing the SP for calling I used the TO_DATE method and convert the String to an Oracle Date as follows,

mightySp('paramName',TO_DATE(:paramName,'yyyy/mm/dd:hh:mi:ssam')

When supplying the parameter, I gave as follows,

tempPlsqlBlock.declareParameter(new SqlParameter("paramName", Types.VARCHAR));

About the Author

Gunith
A trying artist. An admirer of art (code, music, movies & photography). A trying Buddhist. An unknown for the most. A complexity for a lot. A known by a few.. Thats me! Gunith


0 comments »

0 Comments


Be the first to comment!


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>