Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8988061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:56:13+00:00 2026-06-15T21:56:13+00:00

I wrote a java servlet program but when i run it, It was showing

  • 0

I wrote a java servlet program but when i run it, It was showing the error HTTP Status 500 – java.util.Date cannot be cast to java.sql.Date I searched how to any other way for inserting date type to the database but i didn’t got possible way to do so.My code is :

   package skypark;
    import java.io.*;
    import javax.servlet.*;
    import java.text.*;
    import javax.servlet.http.*;
      import java.sql.*;
      import java.sql.Date;
  public class Registration extends HttpServlet
 {
  /**
   * 
   */
     private static final long serialVersionUID = 1L;
     public static Connection prepareConnection()throws ClassNotFoundException,SQLException
{
String dcn="oracle.jdbc.driver.OracleDriver";
String url="jdbc:oracle:thin:@JamesPJ-PC:1521:skypark";
String usname="system";
String pass="tiger";
Class.forName(dcn);
return DriverManager.getConnection(url,usname,pass);
  }
  public void doPost(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException
 {
resp.setContentType("text/html");
PrintWriter out=resp.getWriter();
try
{
String phone1,dofb,date1,month,year,uname,fname,lname,address,city,state,country,pin,email,password,gender,lang,qual,relegion,privacy,hobbies,fav;

uname=req.getParameter("uname");
fname=req.getParameter("fname");
lname=req.getParameter("lname");
date1=req.getParameter("date");
month=req.getParameter("month");
year=req.getParameter("year");
address=req.getParameter("address");
city=req.getParameter("city");
state=req.getParameter("state");
country=req.getParameter("country");
pin=req.getParameter("pin");
email=req.getParameter("email");
password=req.getParameter("password");
gender=req.getParameter("gender");
phone1=req.getParameter("phone");
lang="";
qual="";
relegion="";
privacy="";
hobbies="";
fav="";
dofb=date1 +"-"+ month +"-" + year;
int phone=Integer.parseInt(phone1);
DateFormat formatter ; 
java.util.Date dob ; 
formatter = new SimpleDateFormat("dd-MM-yy");
dob = formatter.parse(dofb); 

Connection con=prepareConnection();
String Query="Insert into regdetails values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement ps=con.prepareStatement(Query);
ps.setString(1,uname);
ps.setString(2,fname);
ps.setString(3,lname);
ps.setDate(4,(Date) dob);
ps.setString(5,address);
ps.setString(6,city);
ps.setString(7,state);
ps.setString(8,country);
ps.setString(9,pin);
ps.setString(10,lang);
ps.setString(11,qual);
ps.setString(12,relegion);
ps.setString(13,privacy);
ps.setString(14,hobbies);
ps.setString(15,fav);
ps.setString(16,gender);

int c=ps.executeUpdate();

String query="insert into passmanager values(?,?,?,?)";
PreparedStatement ps1=con.prepareStatement(query);

ps1.setString(1,uname);
ps1.setString(2,password);
ps1.setString(3,email);
ps1.setInt(4,phone);

int i=ps1.executeUpdate();

if(c==1||c==Statement.SUCCESS_NO_INFO && i==1||i==Statement.SUCCESS_NO_INFO)
{
    out.println("<html><head><title>Login</title></head><body>");
    out.println("<center><h2>Skypark.com</h2>");
    out.println("<table border=0><tr>");
    out.println("<td>UserName/E-Mail</td>");
    out.println("<form action=login method=post");
    out.println("<td><input type=text name=uname></td>");
    out.println("</tr><tr><td>Password</td>");
    out.println("<td><input type=password name=pass></td></tr></table>");
    out.println("<input type=submit value=Login>");
    out.println("</form></body></html>");
}
else
{
    out.println("<html><head><title>Error!</title></head><body>");
    out.println("<center><b>Given details are incorrect</b>");
    out.println(" Please try again</center></body></html>");
    RequestDispatcher rd=req.getRequestDispatcher("registration.html");
    rd.include(req,resp);
    return;
  }
 }
  catch(ClassNotFoundException cnfe) {
  out.println("<html><head><title>Error!</title><body>");
  out.println("<b><i>Class not found "+ cnfe +"</i></b>");
  out.println("</body></html>");
} catch(SQLException sqle) {
     out.println("<html><head><title>Error!</title><body>");
      out.println("<b><i>Unable to process try after some time Sql error</i></b>");
      out.println("</body></html>");
} catch (ParseException e) {
     out.println("<html><head><title>Error!</title><body>");
      out.println("<b><i>Unable to process Parseint exc " + e +"</i></b>");
      out.println("</body></html>");
}
 /* catch(Exception e)
 {
   out.println("<html><head><title>Error!</title><body>");
  out.println("<b><i>Unable to process try after some time</i></b>");
  out.println("</body></html>");
  RequestDispatcher rd=req.getRequestDispatcher("registration.html");
  rd.include(req,resp);
  return;
}*/
out.flush();
out.close();
}
}

The error was

 HTTP Status 500 - java.util.Date cannot be cast to java.sql.Date
type Exception report
message java.util.Date cannot be cast to java.sql.Date
description The server encountered an internal error that prevented it from fulfilling this request.
exception
 java.lang.ClassCastException: java.util.Date cannot be cast to java.sql.Date
skypark.Registration.doPost(Registration.java:67)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
 note The full stack trace of the root cause is available in the Apache Tomcat/7.0.33logs.

Please any one help me for resolve this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:56:14+00:00Added an answer on June 15, 2026 at 9:56 pm

    The PreparedStatement.setDate() method expects a java.sql.Date as argument. You have a java.util.Date which is not a java.sql.Date, and you’re trying to cast it to a java.sql.Date. That can’t work. Casting doesn’t change the type of an object.

    To create a java.sql.Date from a java.util.Date, use

    java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a Java Servlet program but when I run it, it was showing
The filter I wrote threw ClassCastException [Ljava.security.cert.X509Certificate; cannot be cast to java.security.cert.X509Certificate when I
I am learning java servlet programming and I wrote a program to upload files,
I wrote some code to read a file in my Java Servlet class. (I'm
so I wrote a Java program to change the IP of a machine. public
I just want to output current and I wrote import java.util.*; at beginning, and
I'm trying to convert an old Delphi program I wrote into Java to compile
Unix gurus! I have a Java program which passes some parameters to a Servlet
I wrote a little Java servlet that would dynamically generate an image button given
I wrote a Java servlet filter on my local machine and deployed it a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.