Insert date into Oracle with PrepareStatement

I am trying to get three variables from 3 drop down meus in a form.  The drop down menus are labled as day, month, and year.  Then I need to insert the daye into the date field in oracle of type date.

My code looks like this:

$MYSQL_edit = "UPDATE news SET news_header=?, subtitle=?, news_teaser=?, news_body=?, news_photo=?, photo_text=?, incld=?, incldhome=?, us=?, europe=?, canada=?, asia=?, intercont=?, location1=?, location2=?, location3=?, datestamp=? WHERE news_id=?";
String $datestamp = $year+"-"+$month+"-"+$day;
out.println("datestamp="+$datestamp);
PreparedStatement editStatement = conn.prepareStatement($MYSQL_edit);
editStatement.setString(1, $news_header);
editStatement.setString(2, $subtitle);
editStatement.setString(3, $news_teaser);
editStatement.setString(4, $news_body);
editStatement.setString(5, $news_photo);
editStatement.setString(6, $photo_text);
editStatement.setInt(7, $incld_int);
editStatement.setInt(8, $incldhome_int);
editStatement.setInt(9, $us_int);
editStatement.setInt(10, $europe_int);
editStatement.setInt(11, $canada_int);
editStatement.setInt(12, $asia_int);
editStatement.setInt(13, $intercont_int);
editStatement.setInt(14, $location1_int);
editStatement.setInt(15, $location2_int);
editStatement.setInt(16, $location3_int);
editStatement.setString(17, $datestamp);
editStatement.setInt(18, $next_num);
int rs2 = editStatement.executeUpdate();

The error I am getting is this:

SQLException(news-edit): ORA-01861: literal does not match format string
Do I have to use a special command to insert the date type field?

Can someone please help me with my code or show me some code that will work?

Thanks,
MD
mderbinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(year, month, day);
java.sql.Date date = new java.sql.Date(cal.getTime().getTime());
editStatement.setDate(17, date);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CodingExpertsCommented:
1) download servlet.jar
2) go to file -> new->project
3) click on java project in the widow that opens up and do next
4) specify the project name and do next
5) go to the libraries and select "ADD EXTERNAL JAR" and specify the location of servlet.jar and do finish
6) NOw run your code.


CE
0
CodingExpertsCommented:
sorry!!!! was meant to be posted for a different question .....
 you may use this function to format your date type. ..

 call using >> easyDateFormat("MM/dd/yy",datestamp);
  public String easyDateFormat (String format, Date dt)
  {
    SimpleDateFormat formatter = new SimpleDateFormat(format);
    String datenewformat = formatter.format(dt);
    return  datenewformat;
  }
0
siliconeagleCommented:
editStatement.setDate(17, new java.sql.Date((new java.util.Date()).getTime()));

you shoud also be aware that you dont need to prefix you variables with $ in java, since all variables are declared then the compiler knows variables explicitly and the use of the $ goes against establised java coding standards. Usually variables and methods are declared with a lowercase letterfirst and each word in the name starting with an uppercase method. e.g:-
int thisIsMyVariable=0; // variable declaration
public void thisIsMyMethod(String thisIsMyParameter) throws Exception{...} // method declaration.

only class name start in uppercase e.g:-
class ThisIsMyClass {}
when it is used you use the lower case equivalent:-
ThisIsMyClass thisIsMyClass = new ThisIsMyClass();

but i guess you didn't aks this anyway :) , some people get huffy though as they are used to reading java code this way.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.