Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@apache.org Received: (qmail 20317 invoked from network); 11 Feb 2002 18:45:28 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 11 Feb 2002 18:45:28 -0000 Received: (qmail 8099 invoked by uid 97); 11 Feb 2002 18:45:09 -0000 Delivered-To: qmlist-jakarta-archive-tomcat-user@jakarta.apache.org Received: (qmail 7893 invoked by uid 97); 11 Feb 2002 18:45:07 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 7882 invoked from network); 11 Feb 2002 18:45:07 -0000 Message-ID: <00fa01c1b32c$38c60900$fae2c4cb@globalleafs> From: "Uma Maheswar" To: "Tomcat Users List" References: <88500E0F870AA542B6340D8BC05A9E1B065C14@rup.hugsmidjan.is> Subject: Re: Inserting DATE into SQL server Date: Tue, 12 Feb 2002 00:14:57 +0530 Organization: Sri Durga Fashions MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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" To: "Tomcat Users List" 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