Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

PreparedStatement set date sometimes sets the date one day behind

807580Dec 28 2009 — edited Dec 29 2009
I have a PreparedStatement that sometimes sets the date a day behind. I am saving to a MSSQL DB with a field datetime. I have two identical PreparedStatments, one for insert and one for update. When either is executed, it will sometimes set the date back one day. It's not everytime. Every other or every third one, but it's not consistent. Any help would be appreciated.
ps.setDate(1, Util.parseSqlDate(getParam("CHARGED")));
public class Util {
	public static java.sql.Date parseSqlDate(String datestr) {
		DateFormat sdf = null;
		if (datestr == null)
			return null;
		if (datestr.length() > 8) {
			sdf = new SimpleDateFormat("MM/dd/yyyy");
		}
		else {
			sdf = new SimpleDateFormat("MM/dd/yy");
		}
		java.util.Date d = null;
		try {
		 d = sdf.parse(datestr);
		} catch (ParseException e) {
			return null;
		}
		
		if (d != null) {
			Calendar cal = Calendar.getInstance();
			cal.setTime(d);
			return new java.sql.Date(cal.getTimeInMillis());
		}
		return null;
	}
}
	
        protected String getParam(String name) {
		return (getParamArray(name)== null) ? null : getParamArray(name)[0];
	}
	protected String[] getParamArray(String name) {
		return (String[])params.get(name);
	}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 26 2010
Added on Dec 28 2009
3 comments
589 views