tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <bay...@generationjava.com>
Subject Re: Inserting DATE into SQL server
Date Mon, 11 Feb 2002 18:06:22 GMT
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>


Mime
View raw message