i want to store the date in format yyyy-mm-dd as i am using mysql. i have written code in jsp to convert the format dd-mm-yyyy in above fromat working fine.,but when i am entering the fields in front page it is not updating the database and giving the fallowing error.
i have written servlet for that
the servlet is
import java.io.*;
import javax.servlet.*;
import javax.servlet.http://http.*;
import java.sql.*;
public class ReservationServlet extends HttpServlet {
Connection dbConn = null;
public void init(ServletConfig conf) throws ServletException
{
super.init(conf);
} // end init
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String myInstance = req.getParameter("Instance_Name");
String myFromDate = req.getParameter("final1");
Integer myFromTime = Integer.valueOf(req.getParameter("From_Time"));
String myToDate = req.getParameter("Till_Date");
Integer myToTime = Integer.valueOf(req.getParameter("Till_Time"));
Integer number = new Integer(0); // Would store the allocation number
Integer project_no = new Integer(0); // would store the project number
Integer Project_Manager = new Integer(0); // Would store the project manager number
String Email_Id = null; // Would store the email id of the projectr manager
boolean bool;
if (myInstance.length() != 0)
{
if(establishConnection())
out.println("database created" + myFromDate + myFromTime);
else
out.println("database not created");
if (dbConn == null)
{
out.println("there is nothing in the database");
}
project.DaoAllocation obj = new project.DaoAllocation(dbConn);
try
{
//Setting ofinstance name
obj.setM_instance_name(myInstance);
//Searching for a Allocation Number which can be reserved
if(obj.FetchFreeRecord()) {
number = obj.getM_allocation_no();
project_no = obj.getM_project_no();
out.println("RESERVATION RECORD" + number + project_no);
/*
Searching for the appropriate Project Manager Number
*/
project.DaoProject ProjectObj = new project.DaoProject(dbConn);
if(ProjectObj.fetchByPk(project_no)) {
Project_Manager = ProjectObj.getM_project_mngr_no();
out.println("manager no =" + Project_Manager);
/*
Searching for the appropriate Project Manager Email Id
*/
project.DaoEmployee EmployeeObj = new project.DaoEmployee(dbConn);
if(EmployeeObj.fetchByPk(Project_Manager)) {
Email_Id = EmployeeObj.getM_employee_email_id();
out.println("manager email =" + Email_Id);
project.DaoReservation ReservationObj = new project.DaoReservation(dbConn);
ReservationObj.setM_allocation_no(number);
ReservationObj.setM_instance_name(myInstance);
ReservationObj.setM_starting_date(java.sql.Date.valueOf(myFromDate));
ReservationObj.setM_starting_time(myFromTime);
ReservationObj.setM_ending_date(java.sql.Date.valueOf(myToDate));
ReservationObj.setM_ending_time(myToTime);
ReservationObj.setM_status(new Integer(2)); // 2 means Pending requests for reservation
ReservationObj.setM_project_mngr_no(Project_Manager);
ReservationObj.insert();
}
}
}
else {
out.println("NO RECORD IS EMPTY" + number + project_no);
}
}
catch (Exception objExp){
out.println("what are you doing");
out.println(objExp);
}
}else out.println("Please Fill In The Resource Name");
// end MyOption
//if (Employeelist==null)
/*--gaurav //add first cd to the cart
Employeelist = new Vector(); //first order
Employeelist.addElement(obj);
} // end if
// shount b herere } // end do post
session.putValue("Employee.Employeecart", Employeelist);
String url="/jsp/employee.jsp";
ServletContext sc = getServletContext();
RequestDispatcher rd = sc.getRequestDispatcher(url);
rd.forward(req, res);
}
--- gaurav */
}
private boolean establishConnection()
{
try{
Class.forName("com.mysql.jdbc.Driver");
//dbConn = DriverManager.getConnection(prompt("JDBC URL: ", "jdbc:mysql:///brocade_lab"),
// prompt("User Name: ", "root"),
// prompt("Password: ", "gaurav"));
dbConn = DriverManager.getConnection("jdbc:mysql://localhost/brocade_lab","root","gaurav");
return true;
}catch (ClassNotFoundException cnfe) {
System.err.println("Error lodaing" + cnfe);
return false;
}
catch(SQLException se){
System.err.println(se.getMessage());
return false;
}catch(Exception s){
System.err.println(s.getMessage());
return false;
}
} // end of establisConnection()
}
but when i am submitting the page it is giving error
database creatednull1 RESERVATION RECORD61 manager no =22 manager email =good@jh.com what are you doing java.lang.IllegalArgumentException