File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes VERY URGENT Please help me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "VERY URGENT Please help me" Watch "VERY URGENT Please help me" New topic

VERY URGENT Please help me

koray guclu
Ranch Hand

Joined: Feb 23, 2001
Posts: 59
I have a project I use locales in that project to format the dates. I must use mm.dd.yyyy pattern. I use MSSQL server. I get the dates in format. There is not any problem when I get this and format this.
But I have a problem when I try to insert or update dates. Server excepts format. and end users enters the dates in mm.dd.yyyy format I used the following structure in my JSP page
I want to convert mm.dd.yyyy format to format. I get the start_date as a parameter of JSP page
Locale currentLocale = new java.util.Locale("en", "US");
DateFormat currentDateFormatter = java.text.DateFormat.getDateInstance(java.text.DateFormat.SHORT, currentLocale);
String start_date=request.getParameter("StartDate");
SimpleDateFormat formatter = new SimpleDateFormat ("mm.dd.yyyy");
start_date = formatter.format(new java.util.Date(start_date));
start_date=currentDateFormatter.format(new java.util.Date(start_date));

-----------------------------------------------------<BR> Koray GUCLU ~ the sky has no limit ~<BR> (B.s. Computer Engineer)<BR> Frankfurt am Main, Germany<BR> web : <A HREF="<BR rel="nofollow">" TARGET=_blank><BR></A> mail:<BR>-----------------------------------------------------
Peter den Haan
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Dates, aren't they just lovely. It can be hard not to make an absolute mess of them...
When using dates in queries, inserts and other DML statements, I religiously stick to PreparedStatements. They're more efficient anyway as they can be cached. And you can just call PreparedStatement.setDate() without worrying about date formats at all. If you must, really really must, generate your own string representation for the date, use a java.sql.Date to do it for you. It will generate a SQL-92 standard date representation. But really, use a PreparedStatement.
- Peter
I agree. Here's the link:
subject: VERY URGENT Please help me
It's not a secret anymore!