This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Problem with datetime fields Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Problem with datetime fields" Watch "Problem with datetime fields" New topic

Problem with datetime fields

N Nanda
Ranch Hand

Joined: Feb 09, 2004
Posts: 62
Hi all...
I am using JSP page to insert a date time field into an SQL Server 2000 database. I am not able to do it. Can any1 tell me how to do it. I'll be thankful if he/she can provide a small example. I am providing the code I am using...
My Scenario...
I have a 3 combo boxes showing Day (1 to 31), Month (Jan to Dec) and Year (1970 to 2020). Now in my JSP file I have written...

String strDay=request.getParameter("day");
String strMon=request.getParameter("month");
String strYr=request.getParameter("year");
String dob=strDay+"-"+strMon+"-"+strYr;

In my database operation part (i have used PreparedStatement interface), I have written...
I cannot insert it ... please some1 help me..
N Nanda
eammon bannon
Ranch Hand

Joined: Mar 16, 2004
Posts: 140

I cannot insert it ... please some1 help me..

Hmm. Not very descriptive. Post your error, then we can help.
[ April 06, 2004: Message edited by: eammon bannon ]
N Nanda
Ranch Hand

Joined: Feb 09, 2004
Posts: 62
Thank you for your response, I am getting following error...

type Exception report
description The server encountered an internal error () that prevented it from fulfilling this request.
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 40 in the jsp file: /jsp/project/manage_personal.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\Apache\Tomcat5\work\Catalina\localhost\nnsweb\org\apache\jsp\jsp\project\ cannot resolve symbol
symbol : method setDate (int,java.lang.String)
location: interface java.sql.PreparedStatement
1 error

Bikramjit Singh Bajwa
Ranch Hand

Joined: Nov 23, 2003
Posts: 39
I have noticed that you are passing wrong argument in setDate Method of PreparedStatement. Bellow is the exact method:
setDate(int indexNumber, javax.sql.Date date);
and you are passing
setDate(int indexNumber, String date);
I hope this will solve your problem. Make sure pass javax.sql.Date object not java.util.Date object.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63548

Moving to the JDBC forum.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Problem with datetime fields
It's not a secret anymore!