tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uma Maheswar" <...@globalleafs.com>
Subject Re: Inserting DATE into SQL server
Date Mon, 11 Feb 2002 18:44:57 GMT
Hi,
Thanks for your reply. I am using all the three fileds i.e month, date and
year as Strings in the HTML and calling them in my JSP as string only. I do
not use 01 instead of "jan" , will your statement work out?

Uma
----- Original Message -----
From: "Reynir Hübner" <reynir@hugsmidjan.is>
To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
Sent: Monday, February 11, 2002 11:49 PM
Subject: RE: Inserting DATE into SQL server


another way might be to parse it into java.sql.Date
for example :
  Calendar cal = Calendar.getInstance();
  cal.set(int year, int month, int date);
  java.sql.Date sqlDate = new java.sql.Date(cal.getTime().getTime());


then use sqlDate in your insert statement. this would leave your time
part of the dateTime empty. (00.00.00).
I also sometimes (depending on the database) use java.sql.TimeStamp for
DateTime fields, cause it includes both time and date, but of course
that would not help if you dont have the information needed to populate
the time.

hope it helps,
  -reynir

ps. bayard, when would you not use prepared statements ? my experiments
have shown very improved performance over normal Statements....






> -----Original Message-----
> From: bayard@generationjava.com [mailto:bayard@generationjava.com]
> Sent: 11. febrúar 2002 18:06
> To: Tomcat Users List
> Subject: Re: Inserting DATE into SQL server
>
>
> This is the kind of thing you want to use a PreparedStatement
> for. It will
> take care of the date-formatting for you.
>
> DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
> Date date = format.parse(month+"/"+date+"/"+year);
> PreparedStatement ps = connection.prepareStatement("INSERT INTO test
> VALUES(?)");
>
> ps.setDate(date);
> ps.execute();
>
> or some such code close to that.
>
> Bay
>
> On Mon, 11 Feb 2002, Uma Maheswar wrote:
>
> > Hi,
> > I wanted to insert date values into the database in SQL
> Server.The data
> >
> > type I used in SQL server is "DATETIME". I have <select>
> tags used in
> >
> > HTML page to ask the user select the date. I am doing it in this way
> >
> > month = request.getParameter("month");
> > date = request.getParameter("date");
> > year = request.getParameter("year");
> >
> > totdate = month+"/"+date+"/"+year;
> >
> > insert into test values('"+totdate+"');
> >
> > I get error in Tomcat saying that the data type or the number of
> >
> > columns are mismatched. How do I insert date into SQL server.
> >
> > Thanks for any help.
> >
> > Uma
> >
>
>
> --
> To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
> Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>
>
>

--
To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>




--
To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>


Mime
View raw message