java - Insert date in oracle using prepared statemnt -
my user interface returns date string (01/06/2016 2:30 am)to controller , want insert oracle 10 database changing string date , format (dd-mmm-yy hh:mm:ss a) field date type. below tried getting illegal argument exception .
in controller formatted date , passed service layer through dto
created : 01/06/2016 09:00 pm
simpledateformat fromuser = new simpledateformat("mm/dd/yyyy hh:mm a"); simpledateformat myformat = new simpledateformat("dd-mmm-yy hh:mm:ss a"); string reformattedstr = myformat.format(fromuser.parse(created)); system.out.println("reformattedstr : " + reformattedstr); **reformattedstr 06-jan-16 09:00:00 pm
date formatedate=myformat.parse(reformattedstr); in service through prepared statement trying insert , date , other fields.
stmt.settimestamp (8,new java.sql.timestamp(news.getcreated().gettime()));
can please suggest?
thanks , have updated code, might one.
if column data type timestamp, don't need explicit conversion date. statement.settimestamp() method takes care of it.
there 2 ways create timestamp instance java.util.date object.
new timestamp(date.gettime()) or
timestamp.value(new simpledateformat("yyyy-mm-dd hh:mm:ss").format(date)) the value returned news.getcreated().tostring() method might not returning correctly formatted date - if it's returning formatted date.
please refer javadoc timestamp class more information.
thanks
Comments
Post a Comment