Here is my code. I want to insert the date in 0000-00-00 format.
But
The error shows like this
exception occured in Trainee Status java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.DateHere is my code

<%@ page import="INCLUDES.DBConnection"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<jsp:useBean id="DB" scope="page" class="INCLUDES.DBConnection"/>
<jsp:setProperty name="DB" property="*"/>
<jsp:useBean id="DB1" scope="page" class="INCLUDES.DBConnection"/>
<jsp:setProperty name="DB1" property="*"/>
<%
	int course_id=Integer.parseInt(request.getParameter("course_id"));
	int no_of_papers=0;
	String statement="";
	try
	{
		statement="select no_of_papers from x_masterListOfCourses where course_id=" + course_id;
		DB1.setStatement(statement);
		ResultSet objRs=(ResultSet)DB1.result();
		if(objRs.next())
		{
			no_of_papers=objRs.getInt("no_of_papers");
		}	
	}
	catch(Exception e)
	{
		out.print("error occured while executing the query:" + e);
	}
	try
	{
	    Class.forName("com.mysql.jdbc.Driver");
		Connection con = DriverManager.getConnection("jdbc:mysql://localhost/elearning_datasource?user=root");
		String user_name=(String)session.getAttribute("user_name");
		java.util.Date now=new java.util.Date();
		java.sql.Date date=new java.sql.Date(now.getYear(),now.getMonth(),now.getDate());
		String trainee_id="OL_" + course_id + "_" + user_name; 
		statement="select * from x_master_trainee_detail_online";
		DB.setStatement(statement);
		ResultSet objRsInsert=(ResultSet)DB.resultUpdate();
		objRsInsert.next();
		objRsInsert.updateString("trainee_id",trainee_id);
		session.setAttribute("trainee_id",trainee_id);
		objRsInsert.updateString("user_name",user_name);
		String query;
		query="INSERT INTO x_master_trainee_detail_online (user_name, trainee_id, is_registered, is_paper1_tutorial_viewed, is_paper2_tutorial_viewed, is_paper3_tutorial_viewed, is_paper4_tutorial_viewed, is_paper5_tutorial_viewed, is_attended_exam, course_id, paper1_no_of_attempts, paper2_no_of_attempts, paper3_no_of_attempts, paper4_no_of_attempts, paper5_no_of_attempts, is_paper1_completed, is_paper2_completed, is_paper3_completed, is_paper4_completed, is_paper5_completed, paper1_marks, paper2_marks, paper3_marks, paper4_marks, paper5_marks, doe, no_of_papers) VALUES ('"+user_name+"','"+trainee_id+"','1','0','0','0','0','0','0',"+course_id+",'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','date',"+no_of_papers+")";
		Statement st1 = con.createStatement();
		st1.executeUpdate(query);
		response.sendRedirect("course_step.jsp?result=Enrolled successfully.&course_id=" + course_id);
		
			
		
	}
	catch(Exception e)
	{
		out.print("error occured while inserting: " + e);
	}
%>

Please solve my error

don't put business logic in JSP.
don't create SQL statements like that, use PreparedStatement instead.
the error message is quite clear, you're trying to insert an illegal date.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.