aspose file tools*
The moose likes JDBC and the fly likes Problem with datetime fields Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Problem with datetime fields" Watch "Problem with datetime fields" New topic
Author

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...
PST.setDate(2,dob);
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
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
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\manage_005fpersonal_jsp.java:92: cannot resolve symbol
symbol : method setDate (int,java.lang.String)
location: interface java.sql.PreparedStatement
PST.setDate(4,strDate);
^
1 error

org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:127)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:351)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:415)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:458)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:552)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
Bikramjit Singh Bajwa
Ranch Hand

Joined: Nov 23, 2003
Posts: 39
Hi,
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.
buuurraaaaaaaa...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

Moving to the JDBC forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Problem with datetime fields